Question

Which of the following code will print all odd numbers between 3 and 11, each number separated by a space as shown below 35 7

python programming

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question:
Which of the following code will print odd numbers between 3 and 11, each number separated by a space as shown below:
3 5 7 9 11
Ans:
for i in range(3,12,2):
print(i,end=" ")


Now check with the options, what each loop prints:
1. In the first loop
for i in range(3,11,1):
if i%2 != 0:
print(i,end=" ")
This will print the values: 3 5 7 9 but not 11, because 11 is not included, only up to 10, is included. so we are incrementing it by 1 and the if condition checks if the number is not divisible by 2. If we place 12 in place of 11, then this loop will print the exact same output needed.

2. In the second loop
for i in range(3,10,2):
print(i,end=" ")
This will print the values 3 5 7 9. Here, we are starting from 3, and ending up to 10(10 is excluded) and being incremented by 2 which prints even numbers obviously within 10. we need 11 too. If we change to 12, in place of 10 then this loop will print the exact same output needed.

3. In the third loop,
for i in range(3,11,2):
if i%2 == 0:
print(i,end=" ")
This will not print anything, the thing is we are using a for loop to fetch all the odd numbers and inside the loop, we are checking for even case and then printing if the number is even. so this will never print anything.

4. In the fourth loop,
for i in range(3,12,2):
print(i,end=" ")
This will print the exact same output, which is 3 5 7 9 11 since we are fetching only the odd numbers with an increment of 2 starting from 3 to 12(12 is excluded anyway)

Please check the compiled program and its output for your reference:
main.py 1 print(Loop 1) 2 - for i in range(3,11,1): 3 if i%2 != 0: 4 print(i,end= ) 5 6 print(\n\nLoop 2) 7 for i in ra
Output:
input Loop 1 3 5 7 9 Loop 2 3 5 7 9 Loop 3 Loop 4 3 5 7 9 11 ... Program finished with exit code 0 Press ENTER to exit consol
(Feel free to drop me a comment, If you need any help)

Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...

Add a comment
Know the answer?
Add Answer to:
python programming Which of the following code will print all odd numbers between 3 and 11,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while...

    In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...

  • Write a python function that prints all odd numbers between two given numbers print_odd_numbers(10,20) → 11...

    Write a python function that prints all odd numbers between two given numbers print_odd_numbers(10,20) → 11 13 15 17 19 print_odd_numbers(4,12) → 5 7 9 11 ### Your code here def print_odd_numbers(n1, n2):   

  • Hi, I'm trying to write C code that will print the odd abundant numbers between 1...

    Hi, I'm trying to write C code that will print the odd abundant numbers between 1 and 5000 and I've written a program for it but it doesn't work. If you would be able to help me fix it or point out where I went wrong that would be awesome. # include <stdio.h> int main () {    int getSum(int n) int i, n, j, sum = 0;    /* print initial statement to give context of program*/    printf("...

  • Write the PYTHON code that displays the following numbers: The program should have a header that...

    Write the PYTHON code that displays the following numbers: The program should have a header that displays "Number   Doubled Tripled" above the start of the numbers. If putting all numbers on the same line, then they will need to be separated so you can see he individual number.(https://www.programiz.com/python-programming/methods/built-in/print) The program should display Every whole number from 1 through 35. The program should display that number doubled. The program should also display that number tripled. Make a working version of this...

  • PLEASE DO BOTH OF THESE IN PYTHON!!! AND MAKE SURE THAT I CAN COPY THE CODE....

    PLEASE DO BOTH OF THESE IN PYTHON!!! AND MAKE SURE THAT I CAN COPY THE CODE. 1.) Exercise #1: Design and implement a program (name it PrintSum) that prompts the user for an integer values between 1 and 100. The program then uses a while loop to determine and print out the sum of all values between 1 and the entered value. The program rejects invalid input values with proper message such “Invalid Input. Try again.” Document your code and...

  • Python 3 Write a program that calculates the factorial of the greatest odd number in a...

    Python 3 Write a program that calculates the factorial of the greatest odd number in a sequence of positive numbers (separated by spaces). The program must receive sequences of integers, one per line. The end of the input cases will be indicated by the number -1. For each line the program must print the factorial of the greatest odd number in each sequence. Note that for this question, there is always a greatest positive odd number in each line. Sample...

  • Need some help I am not understanding this programming class at all. We are using Microsoft...

    Need some help I am not understanding this programming class at all. We are using Microsoft visual studio with python in console mode to complete these labs. Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...

  • Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that...

    Java Programming. Write your own source code with comments. (Print distinct numbers) Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct...

  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20

  • Write a Python program that calculates the product of all odd numbers between 1 and 20...

    Write a Python program that calculates the product of all odd numbers between 1 and 20 (1x3x5x7x9x11x13x15x17x19), using the for loop and the range function.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT