0

If statements

num=7 If num>3: Print(“3”) If num <5: Print(“5”) If num ==7: Print(“7”) Answerr >>> 3 Why not >>> 3 7

30th Sep 2018, 2:56 PM
fente
5 Respuestas
+ 5
If the first condition is True, the first indented code block is executed, so "3" is printed and the second condition is evaluated. Since the second condition is False, the second indented code block is not executed, so "5" is not printed and the third condition is not evaluated so "7" is never printed. btw make sure you don't capitalize "if" and "print" 😉
30th Sep 2018, 4:18 PM
David Ashton
David Ashton - avatar
+ 3
Because of the indentation, 3rd if is part of 2nd if. And both depend on 1st. This would give you 3 and 7. num = 7 if num > 3: print(“3”) if num < 5: print(“5”) if num == 7: print(“7”)
30th Sep 2018, 4:57 PM
hamletmun
hamletmun - avatar
+ 2
fente post your code here.
30th Sep 2018, 3:23 PM
Random
Random - avatar
0
it writes 3 because it is first
30th Sep 2018, 3:09 PM
callum willcocks
callum willcocks - avatar
0
I did not write code
30th Sep 2018, 3:23 PM
callum willcocks
callum willcocks - avatar