TypeError: can't multiply sequence by non-int of type 'str' - 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: TypeError: can't multiply sequence by non-int of type 'str' (/thread-5526.html) Pages:
1
2
|
RE: TypeError: can't multiply sequence by non-int of type 'str' - Beatenberg - Oct-10-2017 When I add int to both cost[0] * cost[1], the code repeats itself and never multiplies them. Why is this happening? def Pass_Calculate(cost): return int(cost[0]) * int(cost[1]) RE: TypeError: can't multiply sequence by non-int of type 'str' - sparkz_alot - Oct-10-2017 When does 'Pass_Total()' come into play? RE: TypeError: can't multiply sequence by non-int of type 'str' - Beatenberg - Oct-10-2017 Pass_Total() comes into play after Pass_Discount() def Pass_Show(): print("Aussie Pass!") print("Please select a package and discount depending on age.") print("E.g. Package = 7") Pass_Package() def Pass_Package(): print("7 Day Pass – $139.95") print("14 Day Pass - $239.95") print("30 Day Pass - $500.00") Pass_Discount() def Pass_Discount(): print("Children (Under 15) - 60% off") print("Students (Over 15 & less than 22) - 40% off") print("Seniors (60 or over) - 50% off") Pass_Total() def Pass_Total(): cost = Pass_Cost() total = Pass_Calculate(cost) print("The total cost is: $" + str(total)) def Pass_Cost():#User inputs the type of package they suit and discount cost=list() package = input('Package: ') if package == '7' or '14' or '30': #If they enter those values they will move onto choosing their discount print("Proceed...") cost.append(package) if package not in('7','14','30'): Pass_Cost()#If they do not enter any of those values they will be prompted to ask again p = int(package) discount = input("Discount: ") if discount == "Children": discount = 0.60 cost.append(discount) Pass_Calculate(cost) if discount == "Students": discount = 0.50 cost.append(discount) Pass_Calculate(cost) if discount == "Seniors": discount = 0.40 cost.append(discount) Pass_Calculate(cost) if discount not in ("Children","Students","Seniors"): Pass_Cost() d = int(discount) return p, d def Pass_Calculate(cost): return float(int(cost[0])) * float(int(cost[1])) #Calculates the cost from their chosen package and discount e.g. 7 * 0.6 #7 being the chosen package (7 Day Pass) and 0.6 being the Children discount (60%) Pass_Show() |