Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books. Write a statement that assigns freeBooks the appropriate value based on the values of the boolean variable isPremiumCustomer and the int variable nbooksPurchased.
Source code
isPremiumCustomer=False
n=int(input("Choose the type of customer:\n1. Premium\n2. Regular\n"))
if(n==1):
isPremiumCustomer=True
elif (n==2):
isPremiumCustomer=False
nbooksPurchased=int(input("Enter number of books purchased: "))
free_book=0
if (isPremiumCustomer==True):
if(nbooksPurchased>=5 and nbooksPurchased<8):
free_book=1
elif (nbooksPurchased>=8):
free_book=2
elif (isPremiumCustomer==False):
if(nbooksPurchased>=7 and nbooksPurchased<12):
free_book=1
elif (nbooksPurchased>=12):
free_book=2
print("Free book(s): ",free_book)
Sample output 1
Sample output 2
Sample output 3
Sample output 4
Comments
Leave a comment