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

Help please? TypeError: can't multiply sequence by non-int of type 'str'

P: 7
HELP please?
Im new to python. I made this code but I keep getting:

subtotal= 'shirts' * 'amount' * 0.20

TypeError: can't multiply sequence by non-int of type 'str'



the code is:



shirts="12.99"

amount=input("How many shirts would you like to purchase?")

subtotal= 'shirts' * 'amount' * 0.20

percentage= 'shirts' * 'amount' * 0.20

total= 'subtotal' - 'percentage'
Sep 6 '14 #1
Share this Question
Share on Google+
11 Replies


P: 9
When you put quotes or single quotes around the numbers or words, it reads them as a string of letters, not numbers. Remove the quotes.
Expand|Select|Wrap|Line Numbers
  1. shirts=12.99
  2.  
  3. amount=input("How many shirts would you like to purchase?")
  4.  
  5. subtotal= shirts * amount * 0.20
  6.  
  7. percentage= shirts * amount * 0.20
  8.  
  9. total= subtotal - percentage
  10.  
  11. print subtotal, percentage, total
  12.  
So the error is telling you that you can't use a string of letters to multiply with numbers. Whenever you put quote marks around something, it looks at it like it's a string.
Sep 6 '14 #2

P: 7
thank you. But i encountered another problem. doing so i get:
How many shirts would you like to purchase?6


Execution Successful!


it still doenst give me the total I need
Sep 6 '14 #3

P: 9
Add a print statement at the end like in my example above.
Sep 6 '14 #4

P: 7
thank you again for the help. I really appreciate it.
I did as you said, all i got back is:

print subtotal, percentage, total

^

SyntaxError: invalid syntax



here is the code i put:

shirts=12.99

amount=input("How many shirts would you like to purchase?")

subtotal= shirts * amount * 0.20

percentage= shirts * amount * 0.20

total= subtotal - percentage

print subtotal, percentage, total


My goal here is to get a total. Im trying to get the percentage to be subtracted from the subtotal to get that number. if it makes sense.
Sep 6 '14 #5

P: 9
Try just one print statement and see what it says:

print subtotal
Sep 6 '14 #6

P: 7
thankyou.

I tried
print subtotal

got:

SyntaxError: invalid syntax
Sep 6 '14 #7

P: 9
Are you running this from IDLE or do you have it saved as a script?
Sep 6 '14 #8

P: 7
Im trying them in both IDLE and Ninja
Sep 6 '14 #9

P: 9
Wait....you're probably using a python 3.x version so you have to put parenthesis around things you want to print:

print (subtotal)
Sep 6 '14 #10

P: 7
yep yep I am using python 3.x
and yep yep I have tried both with parenthesis and without.

I changed my code to this:

shirts=12.99

amount=float(input("How many shirts would you like to purchase?"))

subtotal= shirts * amount * 0.20

percentage= shirts * amount * 0.20

total= subtotal - percentage

print (total)


when I print (subtotal) I get the right answer
when I print (percentage) I also get the right answer
but now when I print (total) I get 0.0 no matter what number I input when I run it to test it.
Sep 6 '14 #11

P: 7
OHHHHHHHHHHHHHHH I FIXED IT!! YAY!!
I see what I was doing wrong

I had:

subtotal= shirts * amount * 0.20
percentage= shirts * amount * 0.20

when actually suppose to be:

subtotal= shirts * amount
percentage= shirts * amount * 0.20



oh gee I feel soooo sillyyyyy.
Thank you so much for taking time to help me. I highly appreciate it.
Sep 6 '14 #12

Post your reply

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