+ 1
Python - player vs A.I game
Can anyone tell me how I should go about writing a program that asks for variables from the user, then puts them inside of a random.randint() group for (a,b) I have the part for the A.I. but I can't seem make any progress on the user part, because it tells me it can't convert a string into an integer and I'm confused on how I would write that. Anyone know a solution?
3 odpowiedzi
0
int("5")=5
Use int to convert strings to numbers.
+ 1
Use exec(user_input), python will consider the input as a tuple (in your case (a,b) is a tuple).
EDIT:
a = exec(input(": "))
x = random.randint(x[0], x[1])
0
Aymane Boukrouh I get that part but, I'm trying to get the user inputted numbers to go into random.randint(a,b)'s a and b values, if that's possible.