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)

25th Aug 2016, 1:23 PM
Ezie
6 ответов
+ 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):
25th Aug 2016, 1:46 PM
mrGoldJeff
mrGoldJeff - avatar
+ 2
Use if with a range: value=random.randint(0,5) if value in range(0-2): print("heads") else: print("tails")
25th Aug 2016, 2:15 PM
Eduard Hirsch
Eduard Hirsch - avatar
+ 1
So is there nothing that covers a range of numbers???
25th Aug 2016, 2:03 PM
Ezie
+ 1
also you can use ">", "<", "<=", ">=" I can't remember anything else, sorry :) Maybe somehow using arrays
25th Aug 2016, 2:13 PM
mrGoldJeff
mrGoldJeff - avatar
0
Thanks!
25th Aug 2016, 2:15 PM
Ezie
0
I might have used value<4 and value>3 or value<4 else
25th Aug 2016, 7:07 PM
alan fracas