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

26th Oct 2016, 5:14 PM
Noah Martins
11 Answers
+ 7
print('1,2,3') x = int(input('Enter a no.:')) print(x) if x==4: print("Correct") elif x!=4: print("Nope")
26th Oct 2016, 5:22 PM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 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")
26th Oct 2016, 5:25 PM
PrisseReine
+ 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")
26th Oct 2016, 5:30 PM
Zen
Zen - avatar
+ 4
There were two problems in your code You were not using indundation and you need to convert user input into integer
26th Oct 2016, 5:24 PM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 1
it's else if rather then elif in 6th line
26th Oct 2016, 5:20 PM
KUNARK KHEWAL
KUNARK KHEWAL - avatar
+ 1
or may b u should use else only
26th Oct 2016, 5:21 PM
KUNARK KHEWAL
KUNARK KHEWAL - avatar
+ 1
where is your else selection statement
5th Nov 2016, 4:47 PM
albrtna
albrtna - avatar
0
thanks a lot
26th Oct 2016, 5:25 PM
Noah Martins
0
Go to lesson 1 and copy and paste what they wrote for the code and see how it works IF it works.
26th Oct 2016, 6:35 PM
sophie
sophie - avatar
0
by using else or int
2nd Nov 2016, 12:57 PM
Ranjana Karmhe
Ranjana Karmhe - avatar
0
first you have to ident your code second you need yo convert your input
15th Nov 2016, 1:37 AM
Francisco Javier Coenda
Francisco Javier Coenda - avatar