First time coding multiplication in python but always an error comes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IamSciFi
    New Member
    • Aug 2020
    • 1

    First time coding multiplication in python but always an error comes

    I'm a new at python but have a little bit of exp so I typed
    a code:-
    x=input('Enter the number')
    y=input('Enter the number')
    print('The product of x and y is');x*y=
    END

    But it always saysTraceback (most recent call last):
    File "C:/Users/lapchief/Documents/Python/Python 1st program.py", line 3, in <module>
    print('The product of x and y is');x*y
    TypeError: can't multiply sequence by non-int of type 'str'
    so plz tell is my code correct and if no then plz tell me what correction I need to do here.
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    The input entered is returned as a string.

    Comment

    • hussainmujtaba
      New Member
      • Apr 2020
      • 13

      #3
      You need to convert the inputs to int.Like this
      Code:
      x=int(input('Enter the number'))
      Here is python tutorial for beginners to know more
      Last edited by Rabbit; Sep 1 '20, 03:45 PM.

      Comment

      • Ishan Shah
        New Member
        • Jan 2020
        • 47

        #4
        You should take the integer input or convert it into an integer then perform the multiplication of integers.

        Code:
        mul=int(a)*int(b)
        or

        Code:
        a=int(input("Enter the value of a : "))
        b=int(input("Enter the value of b : "))
        mul=a*b

        Comment

        Working...