Added sample files for day 2 and 3

This commit is contained in:
cheezedoodle2
2023-03-31 12:03:53 -07:00
parent 8f30f2b39b
commit 81a2c615bc
8 changed files with 123 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
for i in range(31):
print(f"{i}: ", end='')
if i % 3 == 0:
print("fizz", end='')
if i % 5 == 0:
print("buzz", end='')
print()
+26
View File
@@ -0,0 +1,26 @@
class TomatoPrice:
price: float
def __init__(self, value):
self.price = value
def __str__(self):
return f"USD${self.price}"
def __radd__(self, operand):
self.price += operand.price
b'abcdefg'
str = b.encode('UTF-8')
for c in str:
if ord(c) >= 32 and ord(c) < 127:
print(c)
vietnam = TomatoPrice(3.0)
japan = TomatoPrice(4.0)
korea = TomatoPrice(5.0)
vietnam + japan
output = "price of tomatoes in countries A, B, C: " + str(vietnam) + " " + str(japan) + " " + str(korea) + " "
print(output)
+18
View File
@@ -0,0 +1,18 @@
import http.server
import socketserver
from urllib.parse import urlparse, parse_qs
class MyRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
output_string = "abcdefg\rhijklmnop"
self.wfile.write(output_string.encode())
PORT = 8000
Handler = MyRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print(f"Serving on port {PORT}")
httpd.serve_forever()
+16
View File
@@ -0,0 +1,16 @@
def validate(str):
for char in str:
if REPLACE ME:
raise ValueError("Crime detected!")
try:
validate("abcdefg")
print("✅ test1 pass!")
except:
print("❌ test1 pass!")
try:
validate("abcdefg\rhijklmnop")
print("❌ test2 fail!")
except ValueError as err:
print("✅ test2 pass!")
+9
View File
@@ -0,0 +1,9 @@
import pickle
data = {
'🍅': 3,
'🌭': 4,
'🍔': 5
}
with open('food.pickle', 'wb') as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
+6
View File
@@ -0,0 +1,6 @@
import pickle
with open('food.pickle', 'rb') as f:
data = pickle.load(f)
pass
+17
View File
@@ -0,0 +1,17 @@
from time import sleep
def animate():
i:int = 0
print("==================================", end='')
while True:
print(f"\r{i} ", end='')
i += 1
sleep(1)
def print_newline():
print("\r", end='')
print("1000", end='')
print_newline()
print("100")
+24
View File
@@ -0,0 +1,24 @@
class Temperature:
temperature: float
def __init__(self, temperature):
self.temperature = temperature
def __add__(self, operand):
if operand.__class__ != '__main__.Temperature':
raise ValueError(f"That's not a temperature object! It's a {operand.__class__}!")
self.temperature += operand.temperature
def __str__(self):
return f"{self.temperature=}"
def insert_object(self, obj):
self.temperature += obj.temperature
if __name__ == "__main__":
oven = Temperature(180.0)
chicken = Temperature(5.0)
print(f"{chicken + oven=}")
oven.insert_object(chicken)