Question

In: Computer Science

The school bookstore wants you to write a Python script to calculate the point of sale...

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.

Examples:

Welcome to the bookstore!

Gift cards are $25.00 each

Each book costs $5.

How many gift cards do you want? 1

How many books do you have? 2

Your subtotal is $35

Your total is $37.8

and

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

Solutions

Expert Solution

# function to print welcome message to the customer
def welcomeMessage():
    print("Welcome to the bookstore!")
    print("Gift cards are $25.00 each")
    print("Each book costs $5.")

# function to return cost of gift cards
def costOfGiftCards(coupons):
    return 25*coupons

# function to return cost of books
def costOfBooks(books):
    return 5*books

# function to return total cost after adding 8% sales tax
# total = subtotal + 0.08 * subtotal = subtotal * 1.08
def saleTax(subtotal):
    return subtotal*1.08

def main():
    welcomeMessage() # function call to welcome customer
    coupons = int(input("How many gift cards do you want? ")) # user input
    books = int(input("\nHow many books do you have? ")) # user input
    subtotal = costOfGiftCards(coupons) + costOfBooks(books) 
    total = saleTax(subtotal) # function call to calculate total
    print("\nYour subtotal is ${0:.2f}".format(subtotal)) # to set precision to 2 decimal places
    print("Your total is ${0:.2f}".format(total))

if __name__ == "__main__":
    main()

Here is the complete running code as per the requirements.
P.S. Precision can be set to 2 decimal places!!


Related Solutions

The school bookstore wants you to write a Python script to calculate the point of sale...
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:...
The school bookstore wants you to write a Python script to calculate the point of sale...
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 to calculate the average length of the game shortest game , longest...
Write a python script to calculate the average length of the game shortest game , longest game and the overall average length of a snake and ladder game The game length is the number of throws of the die. We are asked to write a python script which calculate that together with the average
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write a python script to calculate the average length of the game, Shortest game, longest game...
Write a python script to calculate the average length of the game, Shortest game, longest game and overall length of the game we need a python script that calculates the average length of a snake and ladder game. ie the number of moves it takes a single player to win the game. Then you run the game several times and will compare the results to come up with the required data(length of the game and number of moves )
In this assignment, you will write a Python script to increase the population of each city...
In this assignment, you will write a Python script to increase the population of each city in the world_x database by 10% (rounded). First, add a new column to the "world_x" city table using the following MySQL command: ALTER TABLE `world_x`.`city` ADD COLUMN `Population` DOUBLE NULL DEFAULT NULL AFTER `Info`; The existing population data are stored as JSON datatype in the city table in a field named Info. You learned about JSON data types in Module 2. To obtain the...
How do I write a script for this in python in REPL or atom, NOT python...
How do I write a script for this in python in REPL or atom, NOT python shell Consider the following simple “community” in Python . . . triangle = [ ["top", [0, 1]], ["bottom-left", [0, 0]], ["bottom-right", [2, 0]], ] This is the calling of function. >>> nearestneighbor([0, 0.6], triangle, myeuclidean) 'top' The new point is (0, 0.6) and the distance function is Euclidean. Now let’s confirm this result . . . >>> myeuclidean([0, 0.6], [0, 1]) 0.4 >>> myeuclidean([0,...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
Write a Python script that: Ask the customer for their current bank balance. One thing you...
Write a Python script that: Ask the customer for their current bank balance. One thing you dont have to worry about is whether or not the user enters a negative or positive amount.. Ask the customer if they wish to deposit ('d') or withdraw ('w') from that amount. Ask them to enter the amount of money they are either depositing or withdrawing. This has to be a positive numeric value. If it is negative, you should print an error message...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT