What is problems in this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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")

2nd Mar 2021, 5:06 AM
Vishal
Vishal - avatar
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)
2nd Mar 2021, 5:28 AM
Sharique Khan
Sharique Khan - avatar
+ 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))
2nd Mar 2021, 5:30 AM
Darian Santiago
Darian Santiago - avatar
+ 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()
2nd Mar 2021, 5:33 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
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)
2nd Mar 2021, 5:27 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
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?
2nd Mar 2021, 5:28 AM
Wilbur Jaywright
Wilbur Jaywright - avatar