Python Forum

Full Version: I can't multiply within my code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
We were given a task at school which means we have to code a program that calculates the highest possible wage for a worker at a toy company. This program requires an inputted value to be multiplied but looking at what I have I can't seem to get it to work because I can input 5 and it will do 5*5 but give me the answer 55555
Here is the code:

print ("Please enter how many teddies you have made today")
a = input()
print ("Please enter how many hours you have worked")
b = input()
A = a * 2
B = b * 5
if A>B:
print ("You are getting paid £",A,"great work today!")
else:
print ("You are getting paid£",B,"nice job!")

Any help is much appreciated - Ryan
The call to input() returned a string, not an integer. When multiplied with a scalar (number), a string is repeated that many times, see this example. Note the use of quotes to denote a string.

>>> '5' * 5
Output:
'55555'
If you convert your input to an integer, you will obtain the expected result of 25:

>>> int('5') * 5
Output:
25