thats so strange!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

thats so strange!!

i tried this code but the result is "no output". but why? x = 30 if x < 30: print ("bye") if x >= 30: print ("Hi") thanks a lot

7th Dec 2017, 9:04 AM
Yusuf Nazari
Yusuf Nazari - avatar
5 Answers
+ 3
Never Mess Up Indentation in Python. The Second If is indented twice, which leads second if to not work. See This: x = 30 if x < 30: print ("bye") if x >= 30: print ("Hi")
7th Dec 2017, 9:11 AM
Niush
Niush - avatar
+ 1
thanks to Niush sitaula but the sample of sololearn is like this completely and the result is ok . that is: num = 12 if num > 5: print("Bigger than 5") if num <=47: print("Between 5 and 47")
7th Dec 2017, 9:16 AM
Yusuf Nazari
Yusuf Nazari - avatar
+ 1
Given num = 12 if 12 > 5 TRUE then "Bigger Than 5" if 12 <= 47 TRUE then "Between 5 and 47"
7th Dec 2017, 9:21 AM
Niush
Niush - avatar
+ 1
That's 2 diffrent codes... sololearn examle start with bigger the 5, then smaller then 47. You go for bigger then 30 and then lower/equal to 30. test the sololearn code with num = 4 and you will get the same result "No Output" test yours code with x = 70
7th Dec 2017, 9:23 AM
Amir Galanty
Amir Galanty - avatar
+ 1
thank you amir. I found a soloution in next course, that is "else": x = 30 if x < 30: print ("bye") else: if x >= 30: print ("Hi") but thats very important to use "<=" or ">=" in one of them to define the number 30. thanks to all
7th Dec 2017, 11:47 AM
Yusuf Nazari
Yusuf Nazari - avatar