Question: Write a Python program that uses for loops to perform the following steps.a. Prompt the user to input two positive integers (no zero or negative).
Write a Python program that uses for 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)
Program layout for each step:
#A
for loop
#B
for loop
#C
for loop
#D
for loop
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: 8 a 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: a 8 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: 8 2 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: -2 8 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 8 Odd integers between 2 and 8 are: 3 5 7 Sum of even integers between 2 and 8 = 20 Sum of the squares of odd integers between 2 and 8 = 83 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
Get step-by-step solutions from verified subject matter experts
