Question: 1. change the main function to ask for user's input for quantity and use the user input in object creation. Use while loop to check
1. change the main function to ask for user's input for "quantity and use the user input in object creation. Use "while" loop to check the validity of the input. The quantity has to be greater or equal to 1, and has to be less then or equal to 10,000. 2. in SoftwareSales class, add a function to calculate price increase. The function takes "numberOfYears" as parameter and has a loop which calculates the increased price for the next numberOfYears. The annual increase rate is 3%. For example, if the number of years is 3, the original price is 10 dollars. The function will loop through 3 years and display the price for each year. The formula to calculate for each year is (1+3%)**year*originalPrice. In this example, the first year will then be 10.3, the second year will be 10.61, and the third year will be 10.93. Test this function in the main function.
For Reference:
class SoftwareSales:
disount10To19 = 0.1 discount20To49 = 0.2 discount50To99 = 0.3 discount100Above = 0.4
def __init__ (self, originalPrice, name): self.__originalPrice = originalPrice self.__name = name
def calculateDiscountPrice(self, quantity):
disount = 0 if quantity >= 100: discount = SoftwareSales.discount100Above elif quantity >= 50: discount = SoftwareSales.discount50To99 elif quantity >= 20: discount = SoftwareSales.discount20To49 elif quantity >= 10: discount = SoftwareSales.disount10To19
return (1-discount)*self.__originalPrice
def main(): wordSale = SoftwareSales(117, "MS Word") windowsSale = SoftwareSales(238, "MS Windows")
#quantity is 10, discount is 10%, original price is 117, final price is 105.3 print("The price for MS Word is:", wordSale.calculateDiscountPrice(10)) #quantity is 99, discount is 30%, original price is 238, final price is 166.6 print("The price for MS Windows is:", windowsSale.calculateDiscountPrice(99))
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
