0

I have a problem 2

I am having a new problem with my code: # Number Guessing Game from random import randint print ("Number Guessing Game") score = 0 number = randint (1, 5) print ("Enter a number from 1 to 5") ans = input if ans = number: print ("Correct") score = score + 1 else: print ("You lost") print ("Try again, if you want") The part that I am having a problem with is this part: "if ans = number:" (It wants me to take away the = sign, but will this ruin the code?

26th Apr 2018, 10:54 AM
Yael
3 odpowiedzi
+ 21
mistake #1: = is used to assign value while == is used to compare value... ans == number compares the two values mistake #2: ans = input is wrong it should be ans = input() 👇here's the solution https://code.sololearn.com/c2y4JnW44CfF/?ref=app
26th Apr 2018, 11:01 AM
🌛DT🌜
🌛DT🌜 - avatar
0
You should write if ans == number:
26th Apr 2018, 11:02 AM
Ali Zhussupov
Ali Zhussupov - avatar
0
"==" is for comparing (is A equal to B), and "=" is for assignment(A=5 ,means that variable A now have value 5). Hope that this will help you!
26th Apr 2018, 11:08 AM
Davor Kandic