473,545 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
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("H ow 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 12011
wordone
9 New Member
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
yumiyay
7 New Member
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
wordone
9 New Member
Add a print statement at the end like in my example above.
Sep 6 '14 #4
yumiyay
7 New Member
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("H ow 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
wordone
9 New Member
Try just one print statement and see what it says:

print subtotal
Sep 6 '14 #6
yumiyay
7 New Member
thankyou.

I tried
print subtotal

got:

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

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

Similar topics

5
3476
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, because the dates must have quotes on each side. I just don't know how make the dates right. Well I'll just show you the code and some insert...
4
8032
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 write this code so I am not sure what is happening here. Here is the code snippet: for (item, agent) in self.lItems:
3
2152
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 instantiate in the following ways PQueue<int> pq1; PQueue<int, Functor> pq2; // where Functor is a name of user-defined class I also added...
14
2126
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 Frame (File LeftEx8_2.html) a series of buttons, which when clicked prompt the user to enter information for background color, text color, link...
6
2130
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 do in Approach that appear to require some subtle and complex manipulation in Access. Herein lies my present problem. I have a number of tables,...
23
3241
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 to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
7
2646
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 if I use the web test interface. It also works fine if I call it from an ASP.NET page that has a text box where the XML is pasted and then passed on....
4
3493
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 me what I'm doing wrong here, so I can hope to throw light on the myriad of similar problems I'm having? Thanks :-) Python 2.4.1 (#2, May 6 2005,...
10
1826
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? /*****************************************************************************/ /* */ /* encrypt */
0
891
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. There are a few Text boxes where the user will input their answers. I want the code to check the users input and compare with set answer. If correct...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5341
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1897
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.