I use a randomizer to make random number from 5 to 10. Can't be so hard? I have used it previously on code (+2000 lines of code, too much for here) and no coding errors occurred.
My code is simply easter egg to my game but it broke all my code:
...
def slowp(t):
for l in t:
sys.stdout.write(l)
sys.stdout.flush()
x=random.randint(0.1,0.9)
time.sleep(x)
print("")
if act=="++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>":
slowp("Hey, that is hello world made in brainfuck!")
...
act
is a string whose value is provided by the user simply with act=str(input("type here."))
. It is directly done before this part.
Error message:
Traceback (most recent call last):
File "startgame.py", line 2084, in <module>
slowp("Hey, that is hello world made in brainfuck!")
File "startgame.py", line 140, in slowp
x=random.randint(0.1,0.9)
File "/usr/lib/python3.4/random.py", line 216, in randint
return self.randrange(a, b+1)
File "/usr/lib/python3.4/random.py", line 180, in randrange
raise ValueError("non-integer arg 1 for randrange()")
ValueError: non-integer arg 1 for randrange()
What is the actual problem?
You are trying to pass floating point values to random.randint()
. That function only takes integers.
You need to use the random.uniform()
function instead; it'll produce a uniformly random value between the lower and upper bound (inclusive):
Return a random floating point number N such that a <= N <= b for a <= b and b <= N <= a for b < a.
Demo:
>>> import random
>>> random.uniform(0.1, 0.9)
0.6793304134926453
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With