Python Forum
Quick question/help regarding my variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick question/help regarding my variable
#1
Hello,

My sellPrice variable won't work because it's taking price as a string and trying to multiply it to a number.

Error:
File "ListTest.py", line 10, in <module> sellPrice = price * 1.10 TypeError: can't multiply sequence by non-int of type 'float'
I tried forcing the price to be an int
[price = int(input("Item Price $: "))]
But I get:

Error:
Traceback (most recent call last): File "ListTest.py", line 18, in <module> "Price: $" + price, TypeError: can only concatenate str (not "int") to str
How do I get this to work?
(It's probably a quick fix, but I'm drawing a blank right now)

Thanks in advance.


The code right now:
#Store items and related info in a list

#Create an empty list
Item = []
 
#Elements for the list
name = (input("Item Name: "))
quantity = (input("Item Quantity: "))
price = (input("Item Price $: "))
sellPrice = price * 1.10


ItemInfo = ("Name: " + name, 
            "Quantity: " + quantity, 
            "Price: $" + price,
            "Sell Price: $" + sellPrice)
 
Item.append(ItemInfo) #Appened the ItemInfo to the Item list
     
print(Item) #Print the list
Reply


Messages In This Thread
Quick question/help regarding my variable - by Extra - May-04-2022, 11:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Quick Question about Dictionaries Extra 6 1,867 Apr-29-2022, 08:34 PM
Last Post: Extra
  quick question/excel+python zarize 1 2,283 Dec-06-2019, 05:38 PM
Last Post: Larz60+
  SELECT statement query question using a variable DT2000 2 3,066 Feb-23-2019, 07:35 AM
Last Post: DT2000
  A quick question teczone 4 3,115 Sep-06-2018, 03:44 PM
Last Post: snippsat
  Completely new to coding - quick question Oster22 1 2,723 Jun-19-2018, 08:42 PM
Last Post: Larz60+
  Quick help! Ellisrb 2 2,783 May-02-2018, 11:21 AM
Last Post: ThiefOfTime
  ldap3 question, using a variable in search string gentoobob 1 2,906 Apr-28-2018, 11:16 AM
Last Post: gentoobob
  Quick Lists Question (Count Occurences) EwH006 9 8,098 Nov-16-2016, 04:33 PM
Last Post: Larz60+
  quick question about deleting an object from memory LavaCreeperKing 5 5,870 Nov-12-2016, 04:05 PM
Last Post: LavaCreeperKing
  quick way to convert in both 2 and 3 Skaperen 10 8,820 Nov-03-2016, 04:43 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020