0

whats wrong with my code

please ell me whats wrong with my code when i run this code , i get an error : print("welcome to my first app") code=input("enter a number betwin 7 and 9") if code==7 : print("your number is: 7") else code<=8 : print("your nmber is greater or eqal 8") else code==9 : print ("your number is 9") please tell me thanks

19th Aug 2016, 4:13 PM
reza.sri
reza.sri - avatar
16 Respuestas
+ 1
you should use elif instead of else if code 7 elif code 8 elif code 9
19th Aug 2016, 4:18 PM
june song
june song - avatar
+ 1
well you should share what error did you get
19th Aug 2016, 4:27 PM
june song
june song - avatar
+ 1
i got it you need to make an indent block like this if a: A elif b: B if you use the plyground here, you can see tab button the left on top of keyboard
19th Aug 2016, 4:34 PM
june song
june song - avatar
+ 1
you need to make a space after if-else statement. if number == 1 print "number one" elif number == 2 print "number two" I guess you just dont know what indentation means
19th Aug 2016, 4:47 PM
june song
june song - avatar
19th Aug 2016, 4:50 PM
june song
june song - avatar
+ 1
It's not if else else It is: if ELIF else
22nd Dec 2016, 11:07 PM
Erik Johanson
Erik Johanson - avatar
+ 1
your first mistake is INDENTATION, and also since u want a number between 7 to 9, u use while loop to literate from 7 down to 9. easier than using if and else. I THINK THIS IS WHAT U WANT CHECK MY VERSION OF IT: copy and paste it into playground. print("welcome to myfirst app"); CODE=int(input('Enter a number between 7 to 9')); if CODE<=9: print("your number is",(CODE)) if CODE==8: print('your number is',(CODE)) elif CODE==9: print("your number is",(CODE)) elif CODE<=6: print("It is a number below 7:",(CODE)) else: if CODE>9: print('it is a number above 9:',(CODE)) print("END") in case someone type in a number below 7 or above 9 your code will crash, so I have handled that with my version check it out.
23rd Dec 2016, 11:41 AM
Emmanuel
Emmanuel - avatar
0
this is the error which it's gives me: ERROR: Traceback (most recent call last): File "/home/mataeoh/buildozer/.buildozer/android/app/PyInterpreter/PyInterpreter.py", line 65, in run_script File "<string>", line 4 print("your number is: 7") ^ IndentationError: expected an indented block thanks for your help
19th Aug 2016, 4:31 PM
reza.sri
reza.sri - avatar
0
thanks a lot for helping me but i still not get it what exactly should i done with this code: print("welcome to my first app") code=input("enter a number betwin 7 and 9") if code==7 : print("your number is: 7") elif code<=8 : print("your nmber is greater or eqal 8") elif code==9 : print ("your number is 9") thank you
19th Aug 2016, 4:43 PM
Reza Sarvani
Reza Sarvani - avatar
0
thanks a lot for helping me my problem solved thanks
19th Aug 2016, 5:01 PM
Reza Sarvani
Reza Sarvani - avatar
0
THE FULLY WRIGHT CODE: print("welcome to my first app") code=input("enter a number between 7 and 9") if code==7 : #Use indentation of 4 spaces or 1 TAB print("your number is: 7") #Use elif instead of else elif code<=8 : #again, 4 spacer or 1 TAB print("your nmber is greater or eqal 8") #Again, elif elif code==9 : print ("your number is 9") ----------------------------------------------------------------------- p.s. i would use x = input() int (x) if x == some_number: pass
20th Aug 2016, 9:12 AM
Tom Post
Tom Post - avatar
0
whitespaces ...
20th Aug 2016, 9:12 PM
Shreyash Laddha
Shreyash Laddha - avatar
0
INDENTATION != INDENTATION
21st Aug 2016, 3:20 AM
proRam
proRam - avatar
0
after the if , before writing print command always put a white space
28th Sep 2016, 2:04 PM
Emmanuel
Emmanuel - avatar
- 1
THIS ONE WORK properly, make attention to identiations and the use of if/else if/ else: print("welcome to my first app") code=input("enter a number betwin 7 and 9") if code==7 : print("your number is: 7") elif code<=8 : print("your nmber is greater or eqal 8") else code==9 : print ("your number is 9")
19th Aug 2016, 5:25 PM
Marco Romanin
Marco Romanin - avatar
- 3
i change my code again but it give an error again: print("welcome to my first app") code=input("enter a number betwin 7 and 9") if code==7 : print("your number is: 7") elif code<=8 : print("your nmber is greater or eqal 8") elif code==9 : print ("your number is 9") what should i done? thanks
19th Aug 2016, 4:22 PM
reza.sri
reza.sri - avatar