Jan-03-2021, 07:01 PM
Thanks for your help. I fixed the issue by rounding s_discount in a separate function, and used a similar method in the additional discount function. I was finally able to separate the raw data from the display data.
"""********** Functions """ #func 1: student discount which discounts the current price to 10%. def student_discount(price): s_discount = price * .9 # represents 10% discount return s_discount #returns raw price # used for display only, receives raw student discount def student_rounding_display(display_price): display_price = round(display_price, 2) #round to 2 decimals display_price = "${fprice}".format(fprice=display_price) # takes data type in format and auto-coverts the return as a string, joins with manual inserted $ return display_price #func 2: additional discount for regular buyers which discounts an additional 5% on the current student discounted price # receives raw student discount, and prints display price def additional_discount(s_discount): total_discount = s_discount * .95 #represents a 5% discount on the already reduced 10% discount display_price = total_discount display_price = round(display_price,2) #round to 2 decimals display_price = "${fprice}".format(fprice=display_price) # takes data type in format and auto-coverts the return as a string print(">> Total discount = ", display_price) #return total_discount <--uncomment only if you'd need to use and return the non-rounded varaible, which you don't in this problem """********** Main code """ #enter retail value of a product price = float(input("Enter price: ")) #pass raw price into func 1 for 10% reduction s_discount = student_discount(price) print(">> Student discount price = ", student_rounding_display(s_discount)) #ask user if further 5% should be included user_input = input("\nInclude another 5% discount? Press 'y' or 'n': ") if user_input == 'y': # pass the 10% price reduction outcome into func 2 for further 5% reduction additional_discount(s_discount) else: print(">> No further discounts, final price was student-only discount: ", student_rounding_display(s_discount))