Python converts string to integer for multiplication

I realize this is probably simple and basic for you guys for my homework with kids and I have no experience or idea on using Python. She needs to get the code to request the number, multiply it by 9 and show the result. She uses the code below, however, it repeats a number instead of multiplying it. (i.e. it shows 3 * 9 as 999 instead of 27). From what I've read, it seems like it has to do with integer multiplication by strings (although I could be wrong). Any help would be greatly appreciated.

number=input("Enter a number to multiply by 9 ")
number=number*9
print('the answer is '+number)

      

+3


source to share


1 answer


Wrap input

in int

orfloat

number=int(input("Enter a number to multiply by 9 "))

      

or



number=float(input("Enter a number to multiply by 9 "))

      

This is because it input

accepts strings and you need to convert them to numbers.

0


source







All Articles