\ Angelly's Python Programming
Angelly Fitzpatrick

Python

Work from My Python Programming Class

Assignment 1


name = "Angelly"
x = 319
print("Hello, welcome to my python program! My name is", name+ ".")
print("The value of x is 319. The result of (4x + 3)/0.2 is",((4*x + 3)/0.2))
               


Assignment 2


               # 1. Restaurant Heading
restaurant_heading = ("Bluey & Bingo's Diner Receipt\n")
print(restaurant_heading)

# 2. Menu item and price per line
table_order = ['Empanadas', 'Pretzel & Beer Cheese', 'Chicago Deep Dish', 'Cincinnati Chili', 'Ginger Ale', 'Fanta', 'Cafe Cubano', 'Pavlova']
menu_prices = [8.55, 12.99, 25.99, 14.99, 2.85, 2.85, 3.99, 6.99]

for items in range(len(table_order)):
               print(table_order[items], "- ${}".format(menu_prices[items]))
# 3. A total
total = 0
for price in menu_prices:
    total+=price
    tax = total*0.1075
    grand_total = total + tax
    tip_1 = grand_total*0.18
    tip_2 = grand_total*0.15
    tip_3 = grand_total*0.10
# 4. The amount of tax on the order. Illinois state tax plus Cook county tax makes it a lovely 10.75% sales tax rate

# 5. A grand total
print()
print('Total: ${}'.format(round(total,2)))
print('Tax 10.75%: ${}'.format(round(tax,2)))
print('Grand Total: ${}'.format(round(grand_total,2)))

print()

# 6. A goodbye message
goodbye_message =('Thank you for your patronage. \nOnline Orders Now Available on DoorDash! \nVisit our website @ www.BlueyBingoDiner.com')
print(goodbye_message)
print('\n10% Tip: ${}'.format(round(tip_3,2)))
print('15% Tip: ${}'.format(round(tip_2,2)))
print('18% Tip: ${}'.format(round(tip_1,2)))

               
            


Assignment 3


legal_colors = ['R', 'G', 'B', 'Y', 'W', 'O', 'M', 'V']


def generate_color_sequence():
    import random
    random.seed()

    sequence = random.sample(range(len(legal_colors)), 4)
    return [legal_colors[i] for i in sequence]

colors = generate_color_sequence()

### You Code Here


# Title and instructions
print("                            MASTERMIND")
print("---------------------------------------------------------------------")
print("Possible colors are (R)ed, (G)reen, (B)lue, (Y)ellow, (W)hite, (O)range, (M)agenta, (V)iolet")
print("Please enter your guess with no spaces between colors. \nColors cannot be repeated")

# I imported counter to remember insertion order.

from collections import Counter 

for i in range(5):

    while True:
# Allows for answers to be lowercase or uppercase
        guess = input(f"Guess {i+1} : ").upper()

        store = Counter(guess)

        flag = 0

# Error message if colors are repeated      
        for color,count in store.items():
            if count > 1 :
                print("Colors cannot be repeated, try again!")
                flag = 1
                break
# Error Message if wrong letter input
            elif color not in legal_colors:
                print(f"{color} is not a valid color, try again!")
                flag = 1
                break
            
 # Error message for more than 4 letters
            if len(guess) > 4 :
                print ("No more than 4 letters, try again!")
                flag = 1
                break
            
 # Error message for less than 4 letters
            if len(guess) < 4 :
                print ("No less than 4 letters, try again!")
                flag = 1
                break
           
        if flag == 0:
                break

    guess = guess.upper()
    ans = ["_","_","_","_"]
    count = 0 
    i = 0

      
    for a,b in zip(guess,colors):
        if a == b:
# A red peg indicates that a color is correct and in the correct location. 
            ans[i] = "R"
            count += 1
# A white peg indicates that a color is correct, but in the wrong location. 
        elif a in colors:
            ans[i] = "W"

        i+=1
    print("".join(ans))

    if count == 4:
        print("You win!")
        exit(0)
print("You lose!")
               
            


Assignment 4

supplier_data = '{"parts": ["sprocket", "gizmo", "widget", "dodad"], "sprocket": {"price": 3.99, "quantity": 32}, "gizmo": {"price": 7.98, "quantity": 2}, "widget": {"price": 14.32, "quantity": 4}, "dodad": {"price": 0.5, "quantity": 0}}'



# Your code goes here

import json

supplier_data = json.loads(supplier_data)


orders = {}
print("                   Midwest Widget Co.")
print("-----------------------------------------------------------")
print("\nWelcome to the parts ordering system, please enter in a part name, followed by a quantity.")

parts = supplier_data["parts"]
print("\nParts for order are:")
for part in parts:
    print(part)

while True:
    part_name = input("Please enter in a part name, or quit to exit: ")

    if part_name == "quit":
        break
    elif part_name not in parts:
        print("Error, part does not exist, try again")

        continue

    quantity = int(input("Please enter in a quantity to order: "))

    data_quantity = supplier_data[part_name]["quantity"]

    ord_quantity = orders.get(part_name, 0)

    actual_quantity = data_quantity-ord_quantity

    if quantity > actual_quantity:
        print("Error, only {} of {} are available!".format(actual_quantity, part_name))

        continue

    orders[part_name] = ord_quantity + quantity

print("\nYour order")
total = 0
for order in orders:
    price = supplier_data[order]["price"]
    order_price = price * orders[order]
    print("{} - {} @ {:.2f} = {:.2f}".format(order,orders[order], price, order_price))
    total += order_price

print("\nTotal: ${:.2f}".format(total))
print("Thank you for using the parts ordering system!")

               
            


Assignment 5


import database
import supplier
                  
supplier_database = database.Database()
                  
 while True:
   data = input("Enter supplier name, or quit to exit: ")
   if data == "quit":
      break
     s = supplier.Supplier(data)
     print("Part info should be entered in the following format: name, price")
                      while True:
                          part_info = input("Enter part info, or quit to exit: ")
                          if part_info == "quit":
                              print()
                              break
                          try:
                              name, price = part_info.split(",")
                              price = float(price)
                          except:
                              print("Error input - Part info should be entered in the following format: name, price - please try again")
                              continue
                          s.add_part(name, price)
                      supplier_database.add_supplier(s)
                  
                  print("\n\nSupplier database complete!\n")
                  while True:
                      data = input("Please enter in a part name or quit to exit: ")
                      if data == "quit":
                          break
                      
                      supplier, price = supplier_database.find_part(data)
                      if supplier == False:
                          print("Error part does not exist in database")
                      else:
                          print(f"Part {data} is available for the best price at {supplier}. Price: ${price:.2f}")
                  
                  print("\nThank you for using the price database!")