0
Why does this code not work: import random def d6(x): for i in range(x): value=random.randint(1,6) if value==1-3: print("heads") if value==4-6: print("tails") d6(1)
6 Respostas
+ 2
Because "value" will never be -2 (1-3=4-6=-2). Use "or" or "|", like:
if (value==1)or(value==2)or(value==3):
+ 2
Use if with a range:
value=random.randint(0,5)
if value in range(0-2):
print("heads")
else:
print("tails")
+ 1
So is there nothing that covers a range of numbers???
+ 1
also you can use ">", "<", "<=", ">="
I can't remember anything else, sorry :) Maybe somehow using arrays
0
Thanks!
0
I might have used value<4 and value>3 or value<4 else