Problem with "input" statement. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem with "input" statement.

Anytime i try to use the input statement in a program, it always gives me an error output. Example score = input (score) If score <=50 : Print("fair") Print("end") And when i input a value, it always gives me a name error report about 'score'

27th May 2020, 8:49 AM
Ojih Ekene Thaddeus
Ojih Ekene Thaddeus - avatar
7 Answers
+ 3
it should be just score=input() or score=input("score") also considering you need an integer it should be score=int(input())
27th May 2020, 8:51 AM
Abhay
Abhay - avatar
+ 2
It is giving error code: score not defined right?? Try: score = int(input("Enter the score: ")) This is given in the python lesson Read it carefully
27th May 2020, 8:51 AM
Namit Jain
Namit Jain - avatar
+ 2
Only writing input will take a string not an integer.... You cannot compare a string with an integer which is 50 in this case
27th May 2020, 8:54 AM
Namit Jain
Namit Jain - avatar
+ 2
Hey Ojih Jude, The built-in "input" function takes an (optional) string as a parameter that is displayed on the screen so it should always be in quotes if typed directly. Also it evaluates the user input as a string, so if we need integer input we convert the input using int() similarly for float input we use float() for conversion and so on.
27th May 2020, 9:03 AM
Solo L earner
Solo L earner - avatar
+ 2
You got NameError here as you have passed in score as a parameter as input(score), which is considered as string by the input function which was still not defined.
27th May 2020, 9:06 AM
Solo L earner
Solo L earner - avatar
+ 1
By the way the syntax is wrong. It is score=int(input("score")) if score<=50: print('fair') print("end")
27th May 2020, 8:52 AM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
0
Ohh, i get now
27th May 2020, 9:10 AM
Ojih Ekene Thaddeus
Ojih Ekene Thaddeus - avatar