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?
6 ответов
+ 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
0
if (expression is true) {
do this;
}
else if (expression not true) {
do this
}
or
if (!true) {
do this;
}
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')
0
output is 5 random numbers then "D20 has ended", then 5 more random numbers and "D12 has ended"
0
fixed a typo.
- 1
baiegh65u6
dvd
vmmvb6mbvb6.bgbm.hga5
v0mb