By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,397 Members | 1,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,397 IT Pros & Developers. It's quick & easy.

First time coding multiplication in python but always an error comes

P: 1
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.
Aug 17 '20 #1
Share this Question
Share on Google+
3 Replies

dev7060
Expert 100+
P: 335
The input entered is returned as a string.
Aug 17 '20 #2

P: 13
You need to convert the inputs to int.Like this
Expand|Select|Wrap|Line Numbers
  1. x=int(input('Enter the number'))
Here is python tutorial for beginners to know more
Aug 31 '20 #3

P: 37
You should take the integer input or convert it into an integer then perform the multiplication of integers.

Expand|Select|Wrap|Line Numbers
  1. mul=int(a)*int(b)
or

Expand|Select|Wrap|Line Numbers
  1. a=int(input("Enter the value of a : "))
  2. b=int(input("Enter the value of b : "))
  3. mul=a*b
4 Weeks Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.