This year, I decided to try programming. I signed up to take the class because I thought it would be interesting and that I might want to use it in my career. The class is titled, “Programming 1.” We’ve worked on the basics of programming, and have made 4 programs to this date. We used the language of Python. We are currently working on another program called “Guessing Game,” where the user must guess a random number chosen by the computer.

I would like to show my Coffee Shop program in this post. I am proud of it because I believe it is well written and flows nicely. It is way better than all my other programs and so this was a breakthrough program for me. This program is like a coffee shop; the user chooses coffee or tea to purchase and chooses a shipping option.  The program calculates your sales tax based on the state you choose and then prints a receipt for you.

Some things that were challenging were the logistics of making the receipt. I had to use f string formatting to make sure it all lined up correctly, so that took a while. Another thing was the state sales tax, because it was a lot of work to include all of the states. I would’ve added more options if the user wanted more items or more orders if I had time. I tried working on it but it didn’t work for me.

Here is some of my source code from it:

 

def get_order_cost(subtotal, orderShipping, orderTax):
    """calculates total order cost and returns it"""
    subtotal = float(subtotal)
    orderTax = float(orderTax)
    orderShipping = float(orderShipping)
    orderCost = subtotal+orderTax+orderShipping
    return orderCost

def print_receipt(itemCost, itemDesc, itemWeight, shippingMethod, orderShipping, subtotal, state, orderTax, orderCost):
    """prints a nice receipt for user, showing everything they ordered and the prices"""
    print("===========================================================================")
    print("                             RECEIPT")
    print("===========================================================================")
    print(f"{itemDesc}.....{money(itemCost)}/lb  x  {itemWeight}lbs")
    print("===========================================================================")
    print(f"                                        Subtotal  =  {money(subtotal)}")
    print()
    print(f"{shippingMethod:>39} shipping  =  {money(orderShipping)}")
    #
    # This aligns the equal signs so the receipt looks pretty.
    #
    print()
    print(f"{state.upper():>38} sales tax  =  {money(orderTax)}")
    #
    # This makes the input for "state" uppercase when I print it so that it looks more professional.
    #
    print("===========================================================================")
    name = "Total Order Cost"
    print(f"{name:>48}  =  {money(orderCost)}")

This code is showing my conversion of all the prices to get the total cost. After that, it shows how I printed my receipt with the special formatting. I chose this because it took a while to get the receipt and I’m proud of how it looks. I wanted to show how I accomplished it with this source code.

 

Here is my program running:

 

This is the first part of the program. I show instructions and coffee/tea options. Then I let the user pick one. After that, I ask them how much they want of it. As you can see, I account for illegal values (such as 0 or negatives). I then display the shipping options and how much each would cost.

In this part, the user chooses a shipping option. I then ask what state they are in, and they can answer using the abbreviation/postal code. After that, I print the receipt for them, all lined up and formatted nicely. I then ask if they want to make another order. If yes, then it restarts like you can see. If no, the program will end.

Leave a comment

Your email address will not be published. Required fields are marked *