23rd Mar 2018, 3:53 PM
Prakhar Gupta
Prakhar Gupta - avatar
5 ответов
+ 4
You're comparing x to A, but you never even created/assigned anything to a variable A. It'll always be false because A simply doesn't exist in this context. To answer your question, based upon your code, to print 'Ok' you could do this: x=input("Result:") A = x if x == A: print("Ok") else: print("Something wrong") ^That'll create the variable 'A' and assign the value of 'x' to it so that the condition is true, thus printing 'Ok'
23rd Mar 2018, 3:56 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
Change if x== A: to this if x == "A":
23rd Mar 2018, 3:57 PM
ihateonions
+ 3
if x==A
24th Mar 2018, 3:12 PM
Misha
Misha - avatar
+ 2
x is a String in your if condition you must check it against a String litteral (x == "A" or x == 'A') or check it against a variable that contains a String litteral (x == A after initializing A = 'something' or A = "something")
23rd Mar 2018, 3:57 PM
cyk
cyk - avatar
+ 1
thanks
23rd Mar 2018, 3:57 PM
Prakhar Gupta
Prakhar Gupta - avatar