Question
Write a Python program that uses any loops to perform the following steps. a. Prompt the user to input two positive integers (no zero or
Write a Python program that uses any loops to perform the following steps.
a. Prompt the user to input two positive integers (no zero or negative). variables: firstNum and secondNum(firstNum must be less than secondNum). Validate the user's input; prompt the user again if firstNum is not less than secondNum (use for loop).
b. Output all odd numbers between firstNum and secondNum. (use for loop).
c. Output the sum of all even numbers between firstNum and secondNum. (use for loop).
d. Output the sum of the square of the odd numbers between firstNum and secondNum. (use for loop)
***Allow the user to repeat the program. (requires another for loop).
***Use only features in Ch02 'Variables, Expressions and Statements', Ch03 'Conditional Execution', Ch04 'Functions', and Ch05 'Loops and Iterations'.
***Do NOT use lists. Do NOT define any functions.
***Your program output must be exactly the same as the output in the OUTPUT section, except font style.
*************************************************************************************
OUTPUT:
- The bold text is the user's input.
*************************************************************************************
Enter two positive integer numbers. First number must be less than the second number: Enter numbers: 4 z Incorrect Input. Please try again. Enter two positive integer numbers. First number must be less than the second number: Enter numbers:
*************************************************************************************
Enter two positive integer numbers. First number must be less than the second number: Enter numbers: w 9 Incorrect Input. Please try again. Enter two positive integer numbers. First number must be less than the second number: Enter numbers:
*************************************************************************************
Enter two positive integer numbers. First number must be less than the second number: Enter numbers: 5 1 First number must be less than the second number! Please try again. Enter two positive integer numbers. First number must be less than the second number: Enter numbers:
*************************************************************************************
Enter two positive integer numbers. First number must be less than the second number: Enter numbers: -3 9 No negative numbers! Please try again. Enter two positive integer numbers. First number must be less than the second number: Enter numbers:
*************************************************************************************
Enter two positive integer numbers. First number must be less than the second number you enter Enter numbers: 2 10 Odd integers between 2 and 10 are: 3 5 7 9 Sum of even integers between 2 and 10 = 30 Sum of the squares of odd integers between 2 and 10 = 164 Do you want to repeat this program? y/n > y
*************************************************************************************
Enter two positive integer numbers. First number must be less than the second number you enter Enter numbers: 1 9 Odd integers between 1 and 9 are: 1 3 5 7 9 Sum of even integers between 1 and 9 = 20 Sum of the squares of odd integers between 1 and 9 = 165 Do you want to repeat this program? y/n > y
*************************************************************************************
Enter two positive integer numbers. First number must be less than the second number you enter Enter numbers: 11 15 Odd integers between 11 and 15 are: 11 13 15 Sum of even integers between 11 and 15 = 26 Sum of the squares of odd integers between 11 and 15 = 515 Do you want to repeat this program? y/n > n Bye!
***********************************************************************************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started