6

I realise that this is probably simple and basic to you guys, its for my childs homework and I don't have any experience or idea on the use of Python. She needs to get the code to request a number, multiply it by 9 and show the result. She is using the code below, however it repeats the number rather than multiply it. (ie it show 3 * 9 as 999 instead of 27). From what I have read it appears this is something to with multiplying integer by strings (though I may 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)
Steve Keeley
  • 63
  • 1
  • 3

1 Answers1

1

Wrap your input in either int or float

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

or

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

This is done because input accepts strings and you have to convert these to numerals.

Andy
  • 49,085
  • 60
  • 166
  • 233
  • input doesn't accept strings, i mean if you enter 10 it accepts it as an integer itself. – Alfie Nov 30 '14 at 16:21
  • @Alfie, for Python 2, that is correct. For Python 3, that is not. (See [here](http://stackoverflow.com/questions/1964996/specify-input-type-in-python) ). I assumed Python 3 based on the `print` function utilized. – Andy Nov 30 '14 at 16:44