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
Asked Nov 21, 2019
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

Expert Answer

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

Check out a sample Q&A here.

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

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Using DeMorgan's Law, write an expression for the complement of F ifF(x,y,z) = xz' (xy + xz)+ xy'(wz...

A: Expression:

question_answer

Q: If a non-key column determines a key column, which normal form is violated?A) 1NFB) 2NFC) 3NFD) BCNF

A: BCNF:Boyce – Codd Normal Form (BCNF) is based on functional dependencies that in a relationship all ...

question_answer

Q: Python 3.7.4: I'm wasting a second request for the same question because the person who answered the...

A: This question asks about to check year is Leap year or not. So, let's know about Leap Year : Leap Ye...

question_answer

Q: You just installed a new application but users cannot connect to the application remotely. Which fea...

A: Explanation:The feature called “Allow remote access to your computer” can be used to enable or disab...

question_answer

Q: Write a do-while loop that continues to prompt a user to enter a number less than 100, until the ent...

A: Program code #1:

question_answer

Q: Write a function MaxMagnitude() with two integer input parameters that returns the largest magnitude...

A: Below is the approach and the C++ program in which a function is defined with two integer parameters...

question_answer

Q: Within the NTDS folder, which file stores the main Active Directory database? Group of answer choice...

A: Within the NTDS folder, the “Ntds.dit”file stores the main Active Directory database .Hence, option ...

question_answer

Q: What is a disaster recovery plan, and why is it important for the organization? How to evaluate the ...

A: Disaster recovery plan is a formal documentation that includes detailed instructions and structural ...

question_answer

Q: The area of an arbitrary triangle can be computed using the formulaarea = √(s(s–a)(s–b)(s–c))where t...

A: The C++ program will obey the following rubrics:Importing essential header files.Declaring integer d...