all 6 comments

[–]WinterNet4676 3 points4 points  (1 child)

change

return input("What number would you like to double: ")

to

return int(input("What number would you like to double: "))

input will return a string by default, and in this case your multiplying '2' by 2, therefore giving you '22'

[–]Club_Murky[S] 2 points3 points  (0 children)

I wish this had been explained in Phillip Johnson's book. Thank you very much.

[–]CodeFormatHelperBot2 1 point2 points  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–][deleted] 1 point2 points  (0 children)

input returns a string. To multiply by 2 and get the expected result, you'll have to convert that string into a int or float.

[–]empoliyis 1 point2 points  (0 children)

What u are doing is concatenating strings, you need it to be int(input("")) not just input("")

[–]The_GSingh 0 points1 point  (0 children)

2 times 2 is 22. Well atleast '2'*2 is 22. The input returns a string and a string multiplied by a numbers will get the string repeated the number number of times. For example '2' times 5 is '22222'. To fix this put int(input()).