0
Hey, I'm a beginner, and i just wrote this small piece of Python code, but for some reason, it's not running how I wanted it to. Any help would be great.
print('1,2,3') x=input('Enter a no.:') print(x) if x==4: print("Correct") elif x!=4: print("Nope") Even if I do type x=4, it always shows the same result... 1,2,3 Enter the next nmber.:4 4 Nope
11 Respostas
+ 7
print('1,2,3')
x = int(input('Enter a no.:'))
print(x)
if x==4:
print("Correct")
elif x!=4:
print("Nope")
+ 7
You forgot that input returns a string!
After correction:
print('1,2,3')
x = input('Enter a no.:')
print(x)
x = int(x)
if x==4:
print("Correct")
elif x!=4:
print("Nope")
+ 5
As suggested by Kunark, you can use else here:
print('1,2,3')
x = int(input('Enter a no.:'))
print(x)
if x==4:
print("Correct")
else:
print("Nope")
+ 4
There were two problems in your code
You were not using indundation and you need to convert user input into integer
+ 1
it's else if rather then elif in 6th line
+ 1
or may b u should use else only
+ 1
where is your else selection statement
0
thanks a lot
0
Go to lesson 1 and copy and paste what they wrote for the code and see how it works IF it works.
0
by using else or int
0
first you have to ident your code
second you need yo convert your input