"non-integer arg 1 for randrange()" in python libary -
i utilize randomizer create random number 5 10. can't hard? have used on code (+2000 lines of code, much here) , no coding errors occurred.
my code easter egg game broke code:
... def slowp(t): 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, hello world made in brainfuck!") ...
act
string value provided user act=str(input("type here."))
. straight done before part.
error message:
traceback (most recent phone call last): file "startgame.py", line 2084, in <module> slowp("hey, 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 homecoming self.randrange(a, b+1) file "/usr/lib/python3.4/random.py", line 180, in randrange raise valueerror("non-integer arg 1 randrange()") valueerror: non-integer arg 1 randrange()
what actual problem?
you trying pass floating point values random.randint()
. function takes integers.
you need utilize random.uniform()
function instead; it'll produce uniformly random value between lower , upper bound (inclusive):
return random floating point number n such <= n <= b <= b , b <= n <= b < a.
demo:
>>> import random >>> random.uniform(0.1, 0.9) 0.6793304134926453
python python-3.x random
No comments:
Post a Comment