Answer to Question #246213 in Python for John

Question #246213

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.


1
Expert's answer
2021-10-04T03:06:50-0400

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





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS