Search code examples
pythonjupyter-notebookmultiplication

Multiplication in Jupyter Notebook


I am very new to python and coding as a whole, so this might be something very basic. I am trying to execute this code, but instead of multiplying the value, it just doubles the numerical. I have tried changing it multiple times in different places, but nothing works. Here is the code:

num=input("Enter a number:")   
doub=num*2   
print("Double of {0}, is {1}".format(num,doub))

If num is 4, instead of outputting num*2 as 8, it outputs it as 44.

I attached the link to the image as well, hopefully, it is displayed properly here, while I earn some reputation points lol.

Thanks!


Solution

  • You need to convert the num variable from string to integer or decimal:

    num = input("Enter a number:")    
    doub = int(num) * 2  # <-- HERE  
    print("Double of {0}, is {1}".format(num, doub))