HELPPPPP PLEASSEE | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

HELPPPPP PLEASSEE

num = 7 if num > 3: print("3") if num < 5: print("5") if num <= 7: print("7") Why do I only get back 3 and not 3 and 7? Thanks

18th Nov 2018, 8:57 PM
Pauline
Pauline - avatar
4 Answers
+ 2
your code runs the first statement, and since it sees that 7 > 3, it continues and prints 3. The next if statement you ask, is not True, so, it wants to continue on through an else or elif statement. It does print 7 because it does not reach that point. You could change the indentation of the final if statement. I hope this helps!
18th Nov 2018, 9:02 PM
Ben Bistline
Ben Bistline - avatar
0
Because of the indentation. With your current indentation, all the if statements are nested.
18th Nov 2018, 9:02 PM
bullion
0
Thank you it helped me a lot
18th Nov 2018, 9:07 PM
Pauline
Pauline - avatar
0
Ok I’ll try it thanks
18th Nov 2018, 9:11 PM
Pauline
Pauline - avatar