example:
num1=input(‘input the first num: ‘)
num2=input(‘input the second num: ‘)
num3=num1*num2
print(num3)
input the first num: enter the integer on the keyboard and enter
input the second num: once again, the keyboard input integer, press enter
p>
start error: can’t multiply sequence by non-int of type ‘float’
reason: the input () function inputs a string format, so the integer you type on the keyboard isn’t actually a positive integer, it’s a string. So num3=num*num will report an error when executing the statement. Because num1 and num2 are strings, they cannot be multiplied.
solution: num1 and num2 cast into integer
specific solution
1. Change the third line of the code to: num3=int(num1)*int(num2)
2. Change the first and second lines to: num1=int(‘input the first num: ‘)
num2 = int (input (‘ input the first num: ‘))
p>
recommends the first solution
Read More:
- Type error: sequence item 0: expected STR instance, int found
- Type error: cannot unpack non Iterable non type object appears when starting Bert server in Ubuntu system
- The reason and solution of the error of join function: sequence item 0: expected STR instance, int found
- [Solved] RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 ‘mat1‘
- Solve the runtimeerror in RNN: expected scalar type long but found float error
- make Error: error: cast from ‘int32_t*’ {aka ‘int*’} to ‘int’ loses precision [-fpermissive]
- RuntimeError: expected scalar type Double but found Float
- Arithmetic overflow error converting identity to data type int
- TypeError: unsupported operand type(s) for *: ‘range‘ and ‘int‘
- Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +
- Successfully solved the problem of “runtimee” in RESNET dataset classification rror:expected scalar type Long but found Float”
- The Vue elementui switch button uses an int type value
- 43. Implementation of the shortest code of multiply strings | Java
- Error casting p_sequencer, please verify that this sequence/sequence item is intended to execute
- org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType null
- Zero division error: float division by zero
- fatal error LNK1169: one or more multiply defined symbols found
- Default constructor cannot handle exception type FileNotFoundException thrown by implicit super cons
- Pit encountered by entity class data type BigDecimal
- RuntimeError: Found dtype Double but expected Float”