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?
5 ответов
+ 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.
+ 5
x = input()
Here the input is a string.
x = int(input())
This should work.
+ 2
Okay, thanks👌
+ 1
Oh, i understood!)
Thank you 😌
+ 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?