# Write a Python program that uses a for loop with the range function to inspect all integers from 300 down to 1. See page 170-172 to learn about the range function. Code in the loop should find exact multiples of 23 and print them in fields 5 characters wide on one line. The loop should also determine two totals; the total of the even multiples and the total of the odd multiples of 23. When the loop ends, the program should display these two totals.

Question
17 views

Write a Python program that uses a for loop with the range function to inspect all integers from 300 down to 1. See page 170-172 to learn about the range function. Code in the loop should find exact multiples of 23 and print them in fields 5 characters wide on one line. The loop should also determine two totals; the total of the even multiples and the total of the odd multiples of 23. When the loop ends, the program should display these two totals.

check_circle

Step 1

Following is the python program:

• Declare necessary variables to store the number 23 & total count of even and odd numbers in range.
• Use for loop to generate number in range from 300 to 1.
• Use if condition to check if number is multiple of 23 or not.
• Use nested if else condition to check for even and odd numbers.
• If number is even, then increment even counter by 1 else increment odd counter by 1.
Step 2

Code:

#declaring variable to store number 23

number=23

#variable to store total even numbers in range

total_even=0

#variable to store total odd numbers in range

total_odd=0

#for loop to print numbers in range 300 to 1

for z in range(300,1,-1):

#using if condition to check if number is multiple of 23

if(z%number==0):

#print the number that is multiple of 23 followed by 5 spaces

print(z,end='     ')

#if number is even increment even counter by 1

...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Python 