+ 2
Why am i getting NameError? in While Loop
Why am i getting NameError? I am looking to run a while loop till user enters 4 or stop... my code: #Guess game, Guss the number ot enter stop to stop the game lucky_num = 4 guess = eval(input("Enter a number: ")) while guess != lucky_num or guess == "stop": guess = eval(input ("enter again: ")) print ("Done") https://code.sololearn.com/cArrC7NFgZmP/#py
5 ответов
+ 3
1. Do not use eval
2. While condition is wrong, use AND not OR,
use guess!="stop", not guess=="stop"
3. Invert the 2 terms of the condition to avoid int() error when you enter "stop"
https://code.sololearn.com/ct6dFUh4qbha/?ref=app
+ 2
Because you're trying to evaluate "stop", which is an unknown command unless you implement it.
+ 2
even if i dont use eval() it gives error
how do i code without using if condition in while loop?
+ 2
You better rearrange your code a bit. eval is completely useless. You get another exception because you're mixing the types and access input though there is none more.
+ 2
so u mean i. while condition there should be only 1 data type?