Write a Python code of a program that asks the user to enter ten numbers and then display the total and the average of ONLY the odd numbers among those ten numbers.
[Please do not use list for this task]
==========================================================
Sample Input 1:
1
2
3
4
5
6
7
8
9
10
Sample Output 1: The total of the odd numbers is 25 and their average is 5.0
Explanation: The total is 1 + 3 + 5 + 7 + 9 = 25 and the average is 25/5 = 5.0
result = 0
count = 0
first = int(input('Enter the first number: '))
if first % 2 != 0:
result += first
count += 1
second = int(input('Enter the second number: '))
if second % 2 != 0:
result += second
count += 1
third = int(input('Enter the third number: '))
if third % 2 != 0:
result += third
count += 1
forth = int(input('Enter the forth number: '))
if forth % 2 != 0:
result += forth
count += 1
fifth = int(input('Enter the fifth number: '))
if fifth % 2 != 0:
result += fifth
count += 1
sixth = int(input('Enter the sixth number: '))
if sixth % 2 != 0:
result += sixth
count += 1
seventh = int(input('Enter the seventh number: '))
if seventh % 2 != 0:
result += seventh
count += 1
eighth = int(input('Enter the eighth number: '))
if eighth % 2 != 0:
result += eighth
count += 1
ninth = int(input('Enter the ninth number: '))
if ninth % 2 != 0:
result += ninth
count += 1
ten = int(input('Enter the tenth number: '))
if ten % 2 != 0:
result += ten
count += 1
print('The total of the odd numbers is ', result, 'and their average is', result/count)
Comments
Leave a comment