+ 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?

29th Apr 2019, 2:59 AM
EXILE
EXILE - avatar
3 Réponses
0
int("5")=5 Use int to convert strings to numbers.
29th Apr 2019, 6:51 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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])
29th Apr 2019, 9:26 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
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.
29th Apr 2019, 9:22 AM
EXILE
EXILE - avatar