Can’t multiply sequence by non int of type ‘float’

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

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: ‘))

recommends the first solution

Read More: