So I am starting out with Python and thought to make a dice roller for fun. I have created this:
import random
import keyboard
print("Which dice would you like? 6 side or 20 side?")
dice = input()
print("Press the space key to initiate a roll")
while True:
if keyboard.is_pressed(' '):
print(random.randint(0, dice))
Now I go by the assumption that making a random in the range of 0 and a pre-made variable (which has a number in it, not null) should work. I mean, it works in Java and C# so why not here right?
For some reason tho Python hates this, I debugged it and it dies at the print line and gives me this error:
Traceback (most recent call last):
File "C:/Users/kiril/PycharmProjects/Practice/main.py", line 8, in <module>
print(random.randint(0, dice))
File "C:\Python\lib\random.py", line 248, in randint
return self.randrange(a, b+1)
TypeError: can only concatenate str (not "int") to str
What's the problem here? Does it not accept pre-made variables (I mean the random class)? Is it maybe that the input in Python makes everything String (I don't know if it's true but hey maybe, only second day on this language)? How do I fix this?