+ 1

Type Conversion

Guys how do I transfer a string to a integer in this situation? (Or you totally can't anyways) Here is my code: import random num = str(random.randint(1,10)) print('Your number is ' + num + '!') int(num) num += 1 print(num)

20th Aug 2016, 1:30 PM
Replicadoe
3 Answers
+ 2
I don't really understand what you are trying with this piece of code. But I played a little bit with it, so no error occurs. import random num = random.randint(1,10) print('Your number is ' + str(num) + '!') num += 1 print(num)
20th Aug 2016, 3:59 PM
Amarie
+ 2
import random num = str(random.randint(1,10)) print('Your number is ' + num + '!') x = int(num) x += 1 print(x) Also possible
20th Aug 2016, 4:06 PM
Amarie
0
Thanks a lot
21st Aug 2016, 12:34 AM
Replicadoe