1 n = input()
2 if n>=100:print(int(n)/10)
3 else:print(int(n)*10)
Error:
Traceback (most recent call last):
File "1.py", line 12, in <module>
if n>=100:print(int(n)/10)
TypeError: '>=' not supported between instances of 'str' and 'int'
***Repl Closed***
analysis: the data type returned by input() is STR, which cannot be directly compared with integers. You must first replace STR with integers, and use the int() method
therefore, the input variable can be converted to int
1 n = input()
2 n = int(n)
3 if n>=100:print(int(n)/10)
4 else:print(int(n)*10)
Or
1 n = int(input("Input a number:"))
2 if n>=100:print(int(n)/10)
3 else:print(int(n)*10)
Similar Posts:
- Problem solving: error in reading CSV file by Panda: typeerror: invalid type comparison
- Python bug problems and solutions sorted out in recent days
- How to Solve Python Error: slice indices must be integers or None or have
- PaddlePaddle Error: ‘map’ object is not subscriptable
- Keras.utils.to in keras_ Categorical method
- Python calculator error: can’t multiply sequence by non-int of type ‘float’
- Python TypeError: ‘int’ object is not iterable
- [Solved] Python TypeError: sequence item 0: expected str instance, int found
- java.net.SocketException: socket closed
- Python TypeError: not all arguments converted during string formatting