r/pythonhelp • u/Smoll_boi69 • Apr 28 '22
HOMEWORK i keep getting this message saying that i cant multiply a sequence with a non-int of type
code:
burger = int(input("Enter the number of burger:"))
fries = int(input("Enter the number of fries:"))
drink = int(input("Enter the number of drink:"))
total = str((burger * 1.49) + (fries * 0.89) + (drink * 0.99))
tax = int(float(total)) * (int(0.07))
Gtotal = str(total) + str(0.07)
print(("The total before tax is : $") + str(total))
print(("the tax is : $") + (str(total)) * (str(0.07)))
print("The grand total is : $") + str(Gtotal)
tendered = int(input("Enter amount tendered: "))
change = str(Gtotal) - str(tendered)
print("The change is: $") + float(str(change))
error message:
Traceback (most recent call last):
File "main.py", line 18, in <module>
print(("the tax is : $") + (str(total)) * (str(0.07)))
TypeError: can't multiply sequence by non-int of type 'str'
if anyone can find the solution to the error please reply. thank you for the help
:)
3
u/CraigAT Apr 28 '22
The error message is because on the line suggested you are attempting to multiply two strings.
As the other comment suggests, keep everything in number (int or float) until you need to display it.
2
u/MT1961 Apr 28 '22
Uh, what are you trying to do here? If you want to figure out the tax, why did you convert total to a string in the first place?
consider:
total = (burger * 1.49) + (fries * 0.89) + (drink * 0.99)
tax = total * 0.07
print("Tax = ${}".format(tax))