cloning over all the old files
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
menu = {
|
||||
1: {"name": 'espresso', "price": 1.99},
|
||||
2: {"name": 'coffee', "price": 2.50},
|
||||
3: {"name": 'cake', "price": 2.79},
|
||||
4: {"name": 'soup', "price": 4.50},
|
||||
5: {"name": 'sandwich', "price": 4.99}
|
||||
}
|
||||
|
||||
def calculate_subtotal(order):
|
||||
"""Calculates the subtotal of an order.
|
||||
|
||||
[IMPLEMENT ME]
|
||||
1. Add up the prices of all items in the order.
|
||||
2. Round the result to 2 decimal places and return it.
|
||||
|
||||
Args:
|
||||
order (list): A list of dicts, where each dict represents an item with a name and price.
|
||||
|
||||
Returns:
|
||||
float: The subtotal of all item prices, rounded to 2 decimal places.
|
||||
"""
|
||||
print('Calculating bill subtotal...')
|
||||
|
||||
### WRITE SOLUTION HERE
|
||||
subtotal_calc = float(0.00)
|
||||
for item in order:
|
||||
subtotal_calc += item['price']
|
||||
return round(subtotal_calc, 2)
|
||||
|
||||
def calculate_tax(subtotal):
|
||||
"""Calculates the tax of an order.
|
||||
|
||||
[IMPLEMENT ME]
|
||||
1. Calculate 15% of the subtotal.
|
||||
2. Round the tax to 2 decimal places and return it.
|
||||
|
||||
Args:
|
||||
subtotal (float): The subtotal amount.
|
||||
|
||||
Returns:
|
||||
float: The calculated tax amount, rounded to 2 decimal places.
|
||||
"""
|
||||
print('Calculating tax from subtotal...')
|
||||
### WRITE SOLUTION HERE
|
||||
tax_rate = 0.15
|
||||
tax = subtotal * tax_rate
|
||||
return round(tax, 2)
|
||||
|
||||
|
||||
def summarize_order(order):
|
||||
"""Summarizes the order.
|
||||
|
||||
[IMPLEMENT ME]
|
||||
1. Calculate subtotal and tax.
|
||||
2. Compute the total (subtotal + tax) and round to 2 decimal places.
|
||||
3. Extract the item names and return them with the total.
|
||||
|
||||
Args:
|
||||
order (list): A list of dicts, where each dict represents an item with a name and price.
|
||||
|
||||
Returns:
|
||||
tuple: A list of item names and the total amount (rounded to 2 decimal places).
|
||||
"""
|
||||
|
||||
### WRITE SOLUTION HERE
|
||||
item_details = list()
|
||||
for item in order:
|
||||
item_details.append((item['name'], item['price']))
|
||||
subtotal = calculate_subtotal(order)
|
||||
subtotal = round(subtotal, 2)
|
||||
tax = calculate_tax(subtotal)
|
||||
total = round(subtotal + tax, 2)
|
||||
names = [item['name'] for item in order]
|
||||
return names, total
|
||||
|
||||
|
||||
# This function is provided for you and will print out the items in an order
|
||||
def print_order(order):
|
||||
print('You have ordered ' + str(len(order)) + ' items')
|
||||
items = [item["name"] for item in order]
|
||||
print(items)
|
||||
return order
|
||||
|
||||
# This function is provided for you and will display the menu
|
||||
def display_menu():
|
||||
print("------- Menu -------")
|
||||
for selection in menu:
|
||||
print(f"{selection}. {menu[selection]['name'] : <9} | {menu[selection]['price'] : >5}")
|
||||
print()
|
||||
|
||||
# This function is provided for you and will create an order by prompting the user to select menu items
|
||||
def take_order():
|
||||
display_menu()
|
||||
order = []
|
||||
count = 1
|
||||
for i in range(3):
|
||||
item = input('Select menu item number ' + str(count) + ' (from 1 to 5): ')
|
||||
count += 1
|
||||
order.append(menu[int(item)])
|
||||
return order
|
||||
|
||||
'''
|
||||
Here are some sample function calls to help you test your implementations.
|
||||
Feel free to change, uncomment, and add these as you wish.
|
||||
'''
|
||||
def main():
|
||||
order = take_order()
|
||||
print_order(order)
|
||||
names, total = summarize_order(order)
|
||||
|
||||
|
||||
print("Order summary:")
|
||||
for name, price in [(item['name'], item['price']) for item in order]:
|
||||
print(f" {name}: ${price:.2f}")
|
||||
|
||||
print(f"Total: ${total:.2f}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,36 @@
|
||||
# Given the initial statements
|
||||
# s1 = "spam"
|
||||
# s2 = "ni!"
|
||||
|
||||
# Show the result of evaluating each of the following string expressions.
|
||||
|
||||
# a) "The knights who say, " + s2
|
||||
# b) 3 * s1 +2 * s2
|
||||
# c) a1[1]
|
||||
# d) s1[1:3]
|
||||
# e) s1[2] + s2[:2]
|
||||
# f) s1 + s2[-1]
|
||||
# g) s1.upper()
|
||||
# h) s1.upper().1just(4) * 3
|
||||
|
||||
## Initialization
|
||||
s1 = "spam"
|
||||
s2 = "ni!"
|
||||
|
||||
StringValues = {
|
||||
"a": "The knights who say, " + s2,
|
||||
"b": 3 * s1 + 2 * s2,
|
||||
"c": s1[1],
|
||||
"d": s1[1:3],
|
||||
"e": s1[2] + s2[:2],
|
||||
"f": s1 + s2[-1],
|
||||
"g": s1.upper(),
|
||||
"h": s1.upper().ljust(4) * 3,
|
||||
}
|
||||
|
||||
def main():
|
||||
for key, value in StringValues.items():
|
||||
print(f"{key}) {value}")
|
||||
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,13 @@
|
||||
s1 = "spam"
|
||||
s2 = "eggs"
|
||||
num1 = 10
|
||||
num2 = 3.14159
|
||||
|
||||
def main():
|
||||
print(f"That is {num1} {s1} and {num1//2} {s2}")
|
||||
print(f"That is {num1:5} {s1} and {num2:5.2} {s2}")
|
||||
print(f"{num1:0.2f} {num2:0.2f}")
|
||||
print(f"{num1:7.5f}{num2:7.5f}")
|
||||
print(f"Time left {num1:02}:{num2:05.0f}")
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,47 @@
|
||||
gradetable = {
|
||||
"90-100": "A",
|
||||
"80-89": "B",
|
||||
"70-79": "C",
|
||||
"60-69": "D",
|
||||
"0-59": "F"
|
||||
}
|
||||
|
||||
def main():
|
||||
usercontinue = 'yes'
|
||||
while usercontinue == 'yes':
|
||||
try:
|
||||
score = int(input("What was the exam score?: "))
|
||||
|
||||
if 90 <= score <= 100:
|
||||
grade = gradetable["90-100"]
|
||||
elif 80 <= score <= 89:
|
||||
grade = gradetable["80-89"]
|
||||
elif 70 <= score <= 79:
|
||||
grade = gradetable["70-79"]
|
||||
elif 60 <= score <= 69:
|
||||
grade = gradetable["60-69"]
|
||||
elif 0 <= score <= 59:
|
||||
grade = gradetable["0-59"]
|
||||
else:
|
||||
grade = 'invalid score'
|
||||
|
||||
print(f"The letter score of score of the exam was {grade}")
|
||||
|
||||
except ValueError:
|
||||
print("Invalid input. Please enter a number.")
|
||||
|
||||
|
||||
usercontinueprompt = input("Would you like to determine the letter grade of another score? (yes/no): ")
|
||||
usercontinueprompt = usercontinueprompt.lower() #Convert to lowercase once
|
||||
|
||||
if usercontinueprompt == 'yes': #Corrected to assignment
|
||||
usercontinue = 'yes'
|
||||
elif usercontinueprompt == 'no':
|
||||
print("Thanks, have a great day!")
|
||||
usercontinue = 'no' # Corrected typo and assignment
|
||||
else:
|
||||
print("That wasn't a valid selection. Try again")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,4 @@
|
||||
a = "cool"
|
||||
input=("")
|
||||
|
||||
print(a)
|
||||
Reference in New Issue
Block a user