0

Why would an if statement run if it's false*? I thought the if statement is supposed to run when true, and not run when false?

if statement runs when false?

6th Feb 2017, 7:36 PM
Tibi Gurau
Tibi Gurau - avatar
6 odpowiedzi
+ 4
an if statement runs when the condition is matched. just read it out loud: if this is true do that if this is false do that else do that instead
6th Feb 2017, 7:47 PM
Mario L.
Mario L. - avatar
0
if (expression is true) { do this; } else if (expression not true) { do this } or if (!true) { do this; }
6th Feb 2017, 7:41 PM
xum
xum - avatar
0
numberOfDice = int(5) kindOfDice = str("d20") if kindOfDice == str("D20") or str("d20"): for i in range(numberOfDice): diced20 = random.randint(1, 20) print(diced20) elif kindOfDice != str("D20") or str("d20"): print("Not D20") # print(kindOfDice) # print(numberOfDice) print('# D20 has ended') # D12 if kindOfDice == str("D12") or ("d12"): for i in range(numberOfDice): diced12 = random.randint(1, 12) print(diced12) # print(kindOfDice) elif kindOfDice != str("D12") or ("d12"): print("Not D12") print ('# D12 has ended')
6th Feb 2017, 10:35 PM
Tibi Gurau
Tibi Gurau - avatar
0
output is 5 random numbers then "D20 has ended", then 5 more random numbers and "D12 has ended"
6th Feb 2017, 10:42 PM
Tibi Gurau
Tibi Gurau - avatar
0
fixed a typo.
6th Feb 2017, 10:57 PM
Tibi Gurau
Tibi Gurau - avatar
- 1
baiegh65u6 dvd vmmvb6mbvb6.bgbm.hga5 v0mb
6th Feb 2017, 11:34 PM
eduardo rivas