python!TypeError: can't multiply sequence by non-int of type 'float' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: python!TypeError: can't multiply sequence by non-int of type 'float' (/thread-150.html) |
python!TypeError: can't multiply sequence by non-int of type 'float' - shaywune - Sep-24-2016 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 RE: python!TypeError: can't multiply sequence by non-int of type 'float' - Yoriz - Sep-24-2016 Input returns string values to do any maths with the users input they must be converted into a number using float or int. RE: python!TypeError: can't multiply sequence by non-int of type 'float' - shaywune - Sep-24-2016 (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 |