0
What is problems in this
#python 3.7.1 n1,n2,n3=Input('enter three numbers separated by comma') split(",") sum=n1+n2+n3 lists=[n1,n2,n3] count=.count(lists) ans=sum/count print("average=sum/count")
5 Answers
+ 3
I would say take separate inputs as integers cannot be entered with comma
errors:
1. Input is not defined - int(input())
2. count = len(lists)
3. print(ans)
+ 1
Try this way...
n1,n2,n3=Input('enter three numbers separated by comma') split(",")
n1,n2,n3 = float(n1), float(n2), float(n3)
sum= n1 + n2 + n3
lists=[n1,n2,n3]
ans=sum/3
print("average = " + str(ans))
+ 1
3) ah, yes. as Sharique Khan points out, the input comes in as a string, and is never converted to a number. â3â in programming has every method in common with âNot a numberâ and has little in common with 3. you have to convert it using int() or float()
0
1) the dot operator in line 5 has nothing before it. the correct usage of the count method would be: count=lists.count(âthingâ) #how many times the string âthingâ occurs in lists, in your case zero.
I have a feeling you were actually trying to find out how big lists was, in which case you should do: count=len(lists) #results in 3
2) the variable ans is never used. you just print the message âans=sum/countâ at the end. what you should do is: print(ans)
or you can skip the assignment of ans and just do: print(sum/count)
0
on a separate note, much of this code seems redundant. the program knows from the beginning that there are three values, so why does it put them in a list just to count them again?