Write a program in Python programming language, which allows the user to input integer values for variables named lowerLimit and upperLimit. Based on the input values, the program should perform the following tasks:
• Calculate and display all odd numbers within the given range (lowerLimit to upperLimit).
• Calculate and display all even numbers within the given range (lowerLimit to upperLimit).
• Calculate and display the number of total even and odd numbers present within the range (lowerLimit to upperLimit).
*lowerLimit and upperLimit are included within range.
lowerLimit = int(input("Enter the lower limit: "))
upperLimit = int(input("Enter the upper limit: "))
numOdd = 0
print("There are odd numbers:")
for i in range(lowerLimit, upperLimit+1):
if i%2 == 1:
print(i, end=' ')
numOdd += 1
print()
numEven = 0
print("There are even numbers:")
for i in range(lowerLimit, upperLimit+1):
if i%2 == 0:
print(i, end=' ')
numEven += 1
print()
print("There are", numOdd, "odd numbers, and", numEven, " even numbers in totals")
Comments
Leave a comment