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
16 Answers
+ 1
you should use elif instead of else
if code 7
elif code 8
elif code 9
+ 1
well you should share what error did you get
+ 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
+ 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
+ 1
just checkout this
http://www.diveintopython.net/getting_to_know_python/indenting_code.html
+ 1
It's not
if
else
else
It is:
if
ELIF
else
+ 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.
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
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
0
thanks a lot for helping me
my problem solved
thanks
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
0
whitespaces ...
0
INDENTATION != INDENTATION
0
after the if , before writing print command always put a white space
- 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")
- 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