Python Forum
python!TypeError: can't multiply sequence by non-int of type 'float'
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python!TypeError: can't multiply sequence by non-int of type 'float'
#1
I am new to programming. learning python by watching online videos and doing exercises so i guess i qualify as a student.

my exercise is this:

Calculate the total to charge for an order from an online store in Canada
      Ask user what country they are from and their order total
      If the user is from Canada, ask which province
      If the order is from outside Canada do not charge any taxes
      If the order was placed in Canada calculate tax based on the province
     Alberta charge .05% General sales Tax (GST)
     Ontario, New Brunswick, Nova Scotia charge .13% Harmonized sales tax
     All other provinces charge .06% provincial sales tax + .05% GST tax
      Tell the user the total with taxes for their order

Here is the code i wrote to solve the exercise:
country = ""
province =""
gst=0.5
hst=0.13
#0.6%taxes for other provinces
otp=0.6
tax=0
tax1=0
tax2=0
orderTotal=0

country=input('what country are you from?')
if country.upper() == 'CANADA':
    province=input("what province of CANADA are you from?:")
    if province.upper() =='ALBERTA':
        orderTotal =input('what is your order total?:')
        tax=(orderTotal*gst)
        orderTotal=(orderTotal+tax)
        print ('your General sales tax based on your chosen province of %s is %.2f and total order is %.2f' %(province,tax,orderTotal))
    if province.upper()=='ONTARIO' or province.upper()== 'NEW BRUNSWICK' or province.upper()=='NOVA SCOTIA':
        orderTotal =('what is your order total?:')
        tax=(orderTotal *hst)
        orderTotal=(ordertotal+tax)
        print ('your harmonized sales tax based on your chosen province of %s is %.2f and total order is %.2f' %(province,tax,orderTotal))
    elif country.upper=='CANADA' and (province.upper()!='ALBERTA' or province.upper()!= 'ONTARIO' or province.upper()!='NEW BRUNSWICK' or province.upper()!= 'NOVA SCOTIA'):
        province=input('what province of CANADA are you from?: ')
        orderTotal =('what is your order total?:')
        tax1=(orderTotal*otp)
        tax2=(orderTotal *hst)
        orderTotal=(orderTotal+tax1+tax2)
        print ('your provincial sales tax %.2f and GST tax %.2f based on your chosen province of %s is %.2f and total order is %.2f' %(tax1,tax2,province,tax,orderTotal))
else:
    orderTotal =('what is your order total?: ')
    #orderTotal=float(orderTotal)
    print ('your order total is $%.2f' %(orderTotal))
    
Please i need assistance,not only to find out but to understand what exactly i am doing wrong.
I have gone through several variations and while some code compile,they fail the testing phase when i run it.

hope to hear from somebody soon

Thank you so much for your help.
:huh: :huh: :huh: :huh:  :s :s :s
Reply
#2
Input returns string values to do any maths with the users input they must be converted into a number using float or int.
Reply
#3
(Sep-24-2016, 03:31 PM)Yoriz Wrote: Input returns string values to do any maths with the users input they must be converted into a number using float or int.
Hello yoriz,

thank you Yoriz,

Thank you so much.

its like your answer opened my eyes and not only did i see where i was goi9ng wrong but i also saw how to make the code even better.

bless you my friend
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  fixing error TypeError: 'float' object is not subscriptable programmingirl 1 1,477 Jan-28-2023, 08:13 PM
Last Post: deanhystad
  TypeError: unsupported operand type(s) for /: 'str' and 'int' enderfran2006 1 2,596 Oct-01-2020, 09:41 AM
Last Post: buran
  Basic Python Program for Sequence patycanes 7 9,889 Jul-15-2018, 08:53 PM
Last Post: ichabod801
  TypeError: can't multiply sequence by non-int of type 'complex' FeverDream 2 12,688 Jul-12-2018, 11:08 PM
Last Post: DeaD_EyE
  TypeError: can't multiply sequence by non-int of type 'str' rmpadilla73 4 30,400 May-28-2018, 12:21 AM
Last Post: py_learner
  TypeError: can't multiply sequence by non-int of type 'str' Beatenberg 12 13,554 Oct-10-2017, 10:14 PM
Last Post: Beatenberg
  multiply all input arguments if int or float roadrage 5 6,946 Nov-28-2016, 09:53 PM
Last Post: roadrage

Forum Jump:

User Panel Messages

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