0

Strange error

I cant understand why i have error like TypeError: '>' not supported between instances of 'str' and 'int' In this code print(f'my number:') x=input() print(f'computer number:') import random y=random.randint(1,10) print(y) if x>y: print('you win!') else: print('you loose') The > is chek operator, so why the computer is telling me that it isn't in str or int?

21st Sep 2020, 4:41 PM
muhammed hilal
muhammed hilal - avatar
5 Respuestas
+ 9
muhammed hilal , all inputs in python are returned as string by default. So if you want to handle strings, there is nothing special to do. if you want to use an input as integer or float, then you have to convert it to the desired data type.
21st Sep 2020, 5:37 PM
Lothar
Lothar - avatar
+ 5
x = input() Here the input is a string. x = int(input()) This should work.
21st Sep 2020, 4:47 PM
Avinesh
Avinesh - avatar
+ 2
Okay, thanks👌
21st Sep 2020, 6:45 PM
muhammed hilal
muhammed hilal - avatar
+ 1
Oh, i understood!) Thank you 😌
21st Sep 2020, 4:50 PM
muhammed hilal
muhammed hilal - avatar
+ 1
Just to check if i understood right So we print in x int(input()), because later we will check numbers But what if we want to check words?
21st Sep 2020, 5:32 PM
muhammed hilal
muhammed hilal - avatar