- 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
4 Respuestas
+ 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)}')
+ 4
Your attempt first..! Try it now and ask if you get stuck..
+ 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..
+ 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)