cloning over all the old files
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#a
|
||||
print("Hello, world!")
|
||||
#b
|
||||
print("Hello", "World!")
|
||||
#c
|
||||
print("3")
|
||||
#d
|
||||
print("3.0")
|
||||
#e
|
||||
print(2 + 3)
|
||||
#f
|
||||
print("2.0 + 3.0")
|
||||
#g
|
||||
print("2" + "3")
|
||||
#h
|
||||
print("2 + 3 =", 2 + 3)
|
||||
#i
|
||||
print("2 * 3")
|
||||
#j
|
||||
print(2 ** 3)
|
||||
#k
|
||||
print(7 / 3)
|
||||
#l
|
||||
print(7 // 3)
|
||||
@@ -0,0 +1,24 @@
|
||||
#a
|
||||
print("Hello, world!")
|
||||
#b
|
||||
print("Hello", "World!")
|
||||
#c
|
||||
print("3")
|
||||
#d
|
||||
print("3.0")
|
||||
#e
|
||||
print(2 + 3)
|
||||
#f
|
||||
print("2.0 + 3.0")
|
||||
#g
|
||||
print("2" + "3")
|
||||
#h
|
||||
print("2 + 3 =", 2 + 3)
|
||||
#i
|
||||
print("2 * 3")
|
||||
#j
|
||||
print(2 ** 3)
|
||||
#k
|
||||
print(7 / 3)
|
||||
#l
|
||||
print(7 // 3)
|
||||
@@ -0,0 +1,27 @@
|
||||
#performs the conversion and prints to the console
|
||||
def ConvertToMiles():
|
||||
kilometers = float(input("Please provide a number of kilometers that you would like to convert to miles: "))
|
||||
converted_to_miles = kilometers * 0.62
|
||||
print(kilometers, " kilometer(s) is/are equal to " , converted_to_miles , " miles.")
|
||||
askaboutrepeating()
|
||||
|
||||
#Ask the users if they would like to do it again.
|
||||
def askaboutrepeating():
|
||||
print("Looks like that provided you a converted number. Do you want to convert another number? ")
|
||||
answer = str(input("Please respond with yes (y) or no (n) :"))
|
||||
if answer == "y":
|
||||
ConvertToMiles()
|
||||
if answer == "n":
|
||||
exit
|
||||
else:
|
||||
print("Woah, something about what you typed was definitley not correct.")
|
||||
askaboutrepeating()
|
||||
|
||||
# Defines what the script is going to do and calls upon the earlier defined Convert function
|
||||
def main():
|
||||
print("Welcome!\n\n This application was made by David Kifer to take a quantity of kilometers and convert them to miles. In the following prompt, you will be asked to provide the amount of kilometers\n\n ")
|
||||
ConvertToMiles()
|
||||
|
||||
# Call the main app to kick off the app
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#Konditorei Coffee shop
|
||||
def main():
|
||||
pounds = float(input("How many pounds of coffee would you like to order?: "))
|
||||
coffee_price = float(15.50)
|
||||
shipping_price = float(0.99 * pounds + 4.50)
|
||||
grand_total = coffee_price + shipping_price
|
||||
print("That comes to a grand total of $" , grand_total)
|
||||
askaboutrepeating()
|
||||
|
||||
# Ask about repeating
|
||||
def askaboutrepeating():
|
||||
print("Thanks for ordering with me! Would you like to order some more?")
|
||||
answer = str(input("Please respond with yes (y) or no (n) :"))
|
||||
if answer == "y":
|
||||
main()
|
||||
if answer == "n":
|
||||
exit
|
||||
else:
|
||||
print("Woah, something about what you typed was definitley not correct.")
|
||||
askaboutrepeating()
|
||||
|
||||
# Call the main app to kick off the app
|
||||
main()
|
||||
|
||||
@@ -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)
|
||||
@@ -0,0 +1,64 @@
|
||||
s1 = [2, 1, 4, 3]
|
||||
s2 = ["c","a","b"]
|
||||
print("------------Discussion Part 1----------")
|
||||
# s1 + s2
|
||||
print("-----s1 + s2-----")
|
||||
print(s1 + s2)
|
||||
|
||||
|
||||
#b) 3 * s1 + 2 * s2
|
||||
print("--------3 * s1 + 2 * s2-----")
|
||||
print(3 * s1 + 2 *s2)
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
|
||||
#c) s1[1]
|
||||
print("--------s1[1]-----")
|
||||
print(s1[1])
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
|
||||
#d) s1[1:3]
|
||||
print("--------s1[1:3]-----")
|
||||
print(s1[1:3])
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
|
||||
#e) s1 + s2[-1]
|
||||
print("--------s1[1:3]------")
|
||||
print(s1 + [s2[-1]])
|
||||
print()
|
||||
|
||||
print("------------Discussion Part 2----------")
|
||||
#a)s1.remove(2)
|
||||
print(s1.remove(2))
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
|
||||
#b)s1.sort()
|
||||
print(s1.sort())
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
|
||||
#c)s1.append([s2.index("b")]
|
||||
print(s1.append([s2.index("b")]))
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
|
||||
#d)s2.pop(s1.pop(0))
|
||||
print(s2.pop(s1.pop(0)))
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
|
||||
#e)s2.insert(s1[1], "d"
|
||||
print(s2.insert(s1[1], "d"))
|
||||
print(f"This is the value of s1: {s1}")
|
||||
print(f"This is the value of s2: {s2}")
|
||||
print()
|
||||
@@ -0,0 +1,27 @@
|
||||
def removeDuplicates(somelist):
|
||||
seen = set()
|
||||
result = []
|
||||
|
||||
for i in somelist:
|
||||
if i not in seen:
|
||||
seen.add(i)
|
||||
result.append(i)
|
||||
|
||||
return result
|
||||
|
||||
def main():
|
||||
#Create a list with duplicates
|
||||
somelist = [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9]
|
||||
|
||||
#Display the list
|
||||
print(somelist)
|
||||
|
||||
#Use the remove duplicates function to remove duplicate values
|
||||
list_parsed = removeDuplicates(somelist)
|
||||
|
||||
print(list_parsed)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
from graphics import *
|
||||
|
||||
win = GraphWin("My Window", 500, 500)
|
||||
|
||||
while True:
|
||||
key = win.checkKey()
|
||||
if key == "q": #loop exit
|
||||
break
|
||||
if key == "r":
|
||||
win.setBackground("red")
|
||||
elif key == "g":
|
||||
win.setBackground("green")
|
||||
elif key == "b":
|
||||
win.setBackground("blue")
|
||||
elif key == "y":
|
||||
win.setBackground("yellow")
|
||||
elif key == "w":
|
||||
win.setBackground("white")
|
||||
elif key == "p":
|
||||
win.setBackground("purple")
|
||||
elif key == "o":
|
||||
win.setBackground("orange")
|
||||
elif key == "c":
|
||||
win.setBackground("cyan")
|
||||
else :
|
||||
win.close()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user