- 4

Write a python that asks the user to enter ten numbers then display the total and the average of only odd number among those ten

28th Jul 2020, 7:46 PM
Suraiya Binte Akbar(Aaisha)
Suraiya Binte Akbar(Aaisha) - avatar
4 Réponses
+ 7
[edited] I misunderstood a part of the question, so it's modified now: In order to match the task description, i modified the code. (1) use a list to store all input values, using a for loop and a range() (2) create new list from input list with only odd values (3) sum all values from odd list = total (4) use total and divide it by the number of values in odd list = Average value of odd numbers lst = [] for i in range(10): lst.append(int(input('Enter the number: '))) odd = [i for i in lst if i % 2 != 0] print(f'total of odd = {sum(odd)}') print(f'average of odd = {sum(odd)/len(odd)}')
28th Jul 2020, 8:30 PM
Lothar
Lothar - avatar
+ 4
Your attempt first..! Try it now and ask if you get stuck..
28th Jul 2020, 7:50 PM
Jayakrishna 🇮🇳
+ 2
[Need proper identation.. Then it works.. But your program have invalid characters. Are you copied it from any Internet source.. Idk, it just working when I all rewrite..] Suraiya Binte Akbar(Aaisha) Look at this code and how I put indentations sum = 0 for i in range(5): j =int(input("enter number:")) print(j) if not j%2==0 : sum += j print(sum) average=sum/5 print(average) It works, if do you need any changes, reply..
28th Jul 2020, 8:30 PM
Jayakrishna 🇮🇳
+ 1
sum=0 for i in range(10) i=int(input('Enter the number: ') print(i) if not(i℅2==0): sum=sum+i average=sum/5 print(average)
28th Jul 2020, 7:58 PM
Suraiya Binte Akbar(Aaisha)
Suraiya Binte Akbar(Aaisha) - avatar