Skip to content

Commit c5b2d2b

Browse files
authored
pset1 code
1 parent 5abb6df commit c5b2d2b

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

week1/bank/bank.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
greeting = input("Greeting : ").lower().strip()
2+
3+
if "hello" in greeting:
4+
print("$0")
5+
elif 'h' == greeting[0]:
6+
print("$20")
7+
else:
8+
print("$100")

week1/deep/deep.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
answer = input("What is the answer to everything? ").lower().strip()
2+
3+
if answer == "42" or answer == "forty two" or answer == "forty-two":
4+
print("Yes")
5+
else:
6+
print("No")

week1/extensions/extensions.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
filename = input("Filename : ").lower().strip()
2+
filename = '.' + filename.split('.')[-1]
3+
4+
match filename:
5+
case ".gif":
6+
print("image/gif")
7+
case ".jpg" | ".jpeg":
8+
print("image/jpeg")
9+
case ".png":
10+
print("image/png")
11+
case ".pdf":
12+
print("application/pdf")
13+
case ".txt":
14+
print("text/plain")
15+
case ".zip":
16+
print("application/zip")
17+
case _:
18+
print("application/octet-stream")

week1/interpreter/interpreter.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
x, y, z = input("Expression : ").split()
2+
x = int(x)
3+
z = int(z)
4+
match y:
5+
case "+":
6+
print(f"{x+z:.1f}")
7+
case "-":
8+
print(f"{x-z:.1f}")
9+
case "*":
10+
print(f"{x*z:.1f}")
11+
case "/":
12+
print(f"{x/z:.1f}")

week1/meal/meal.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def main():
2+
time = input("What time is it? ")
3+
time = convert(time)
4+
if 7 <= time <= 8:
5+
print("breakfast time")
6+
elif 12 <= time <= 13:
7+
print("lunch time")
8+
elif 18 <= time <= 19:
9+
print("dinner time")
10+
11+
def convert(time):
12+
if time.endswith(" a.m."):
13+
time = time.split(' a.m.')
14+
time = time[0].split(':')
15+
return round(int(time[0]) + int(time[1])/60, 2)
16+
elif time.endswith(" p.m."):
17+
time = time.split(' p.m.')
18+
time = time[0].split(':')
19+
return round(12 + int(time[0]) + int(time[1])/60, 2)
20+
else:
21+
time = time.split(":")
22+
return round(int(time[0]) + int(time[1])/60, 2)
23+
24+
if __name__ == "__main__":
25+
main()

0 commit comments

Comments
 (0)