In: Computer Science
The school bookstore wants you to write a Python script to calculate the point of sale (total cost) of their new 25$ gift cards. They are also running a special, if a customer buys a gift card they can buy all books for 5$ dollars each.
The gift card cost is $25.00 plus $5.00 per book. In addition, there is a sales tax which should be applied to the subtotal and it is 8% (multiply the subtotal by 0.08.)
Requirements:
Write a Python script (with meaningful comments) that has a main() function. Have that main() function call another function to display a welcome to the customer. In the main() function, ask the user how many gift cards they would like and how many books they have picked out. Function requirements are as follows: You must write a function to calculate the cost for the gift card(s), a function to calculate the cost of the books, and a function that takes the subtotal applies the 8% (multiply by 0.08) sales tax then returns the total to main(). Display the subtotal in main(). Round all dollar amounts to 2 decimal places (note: python will truncate unnecessary 0s without formatting so do not worry if output only has the tenths place).
Only function definitions and the call to main() can be at 1st level indentation. For a challenge, see if you can make your main function contain less lines that the other functions.
Example:
Welcome to the bookstore!
Gift cards are $25.00 each
Each book costs $5.
How many gift cards do you want? 2
How many books do you have? 4
Your subtotal is $70
Your total is $75.6
# The code for the required problem is given below with screenshots for the indentation
# and if you feel any problem then feel free to ask
# defining a function to print the welcome message to the user with prices
def funcWelcome():
print("Welcome to the bookstore!\nGift cards are $25.00 each\nEach book costs $5.")
# function for calculating the price of gift cards
def calcGiftCard(nG):
return nG*25
# function for calculating the price of books
def calcBook(nB):
return nB*5
# function for calculating the total from subtotal with applied taxes
def calcTotal(subTot):
return (subTot+0.08*subTot)
# definition of main, here we cannot make the main function
# so that the main function have less lines than other functions
# because we have to call all the functions from main and also
# we have to display the total and subtotal from main as given in the requirements
def main():
funcWelcome()
giftCards=int(input("How many gift cards do you want? "))
books=int(input("How many books do you have? "))
subTotal=calcBook(books)+calcGiftCard(giftCards)
total= calcTotal(subTotal)
print("Your subtotal is $"+str(round(subTotal,2))+"\nYour total is $"+str(round(total,2)))
# calling the main function
main()
OUTPUT:- Data used is from the example given in question.