473,385 Members | 2,028 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,385 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 11996
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....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.