Example:
num1=input('input the first num: ')
num2=input('input the second num: ')
num3=num1*num2
print(num3)
After execution, the result is: input the first num: at this time, enter the integer on the keyboard and press enter
Input the second num: enter the integer again and press enter
Can’t multiply sequence by non int of type ‘float’
Reason: the input() function inputs a string format, so the integer you enter on the keyboard is not a positive integer, but a string format. Therefore, when executing the statement Num3 = num * num, an error will be reported. Because num1 and num2 are both strings, they cannot be multiplied
Solution: convert num1 and num2 into integers
Specific solutions
1. The third line of the code is changed to: Num3 = int (num1) * int (num2)
2. Change the first and second lines to: num1 = int (input (‘input the first num: ‘)
num2=int(input(‘input the first num: ‘))
Similar Posts:
- Python TypeError: can only concatenate str (not “int”) to str
- [Solved] PythonTypeError: ‘<' not supported between instances of 'str' and 'int'
- Keras.utils.to in keras_ Categorical method
- For piix4_ Solution of SMBus * * host SMBus controller not enabled (detailed steps summary)
- python TypeError: an integer is required
- [Solved] Mybatis Mapping Error: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘id’ in ‘class java.lang.String
- syntax error near unexpected token `do [How to Solve]
- How to Solve network error: software caused connection abort (Step-by-step Tutorial)
- Tag code error valueerror: bad input shape()
- [Solved] Git Error: failed: authentication failed for ‘http: XXXX.git / ”