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?

2/6/2017 7:36:48 PM

Tibi Gurau

6 Answers

New Answer


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


if (expression is true) { do this; } else if (expression not true) { do this } or if (!true) { do this; }


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')


output is 5 random numbers then "D20 has ended", then 5 more random numbers and "D12 has ended"


fixed a typo.


baiegh65u6 dvd vmmvb6mbvb6.bgbm.hga5 v0mb