473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
11 11991
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
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
Add a print statement at the end like in my example above.
Sep 6 '14 #4
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
Try just one print statement and see what it says:

print subtotal
Sep 6 '14 #6
thankyou.

I tried
print subtotal

got:

SyntaxError: invalid syntax
Sep 6 '14 #7
Are you running this from IDLE or do you have it saved as a script?
Sep 6 '14 #8
Im trying them in both IDLE and Ninja
Sep 6 '14 #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
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
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

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

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
4
by: ahsan Imam | last post by:
Hello All, I am trying to move an application from python 1.5.2 to 2.3. The code works fine in 1.5.2 but gives the exception (exceptions.TypeError unpack non-sequence) in python 2.3. I did not...
3
by: CoolPint | last post by:
I have implemented a generic priority queue below and tested it works fine, but I have one small problem I cannot understand. I have type parameter F which determines the priority so that users can...
14
by: TrvlOrm | last post by:
OK. After much playing around, I managed to get my frame page this far.. see code below. BUT...there are still errors with it, and what I would like to have happened is this: 1) On the Left...
6
by: John Baker | last post by:
Hi: As those who have looked at this newsgroup recently will realize, I am a neophyte with Access, although I have experienced with Approach (the Lotus product). There are things I could easily...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
7
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine...
4
by: Robin Haswell | last post by:
Okay I'm getting really frustrated with Python's Unicode handling, I'm trying everything I can think of an I can't escape Unicode(En|De)codeError no matter what I try. Could someone explain to...
10
by: Smurff | last post by:
Hi, This code works fine on win and linux but not on hpux. All is compiled with gcc. Can anyone help please? /*****************************************************************************/ /*...
0
by: Bresy | last post by:
How to check textbox inputs -------------------------------------------------------------------------------- Hi I relatively new to VB.Net. And I have to create a sort of quiz type application....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.