Skip to content

Commit 3a56614

Browse files
authored
upload pset3
1 parent e7312f7 commit 3a56614

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

pset3/fuel.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
while True:
2+
try:
3+
x,y = input('Fraction: ').split('/')
4+
x, y=int(x), int(y)
5+
if y<x:
6+
raise Exception
7+
elif y==0:
8+
raise ZeroDivisionError
9+
except:
10+
pass
11+
else:
12+
break
13+
14+
percent = (x/y)*100
15+
if percent <= 1:
16+
print('E')
17+
elif percent >= 99:
18+
print('F')
19+
else:
20+
print(f'{percent:.0f}%')

pset3/grocery.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from collections import OrderedDict
2+
3+
list = {
4+
}
5+
#getting items
6+
while True:
7+
try:
8+
item=input().strip().upper()
9+
except EOFError:
10+
break
11+
else:
12+
if item in list:
13+
list[item]+=1
14+
else:
15+
list[item]=1
16+
#sort list
17+
sorted_keys = sorted(list.keys())
18+
sorted_list = {key:list[key] for key in sorted_keys}
19+
#print list
20+
for item in sorted_list:
21+
print( sorted_list[item], item)

pset3/outdated.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
month = [
2+
"January",
3+
"February",
4+
"March",
5+
"April",
6+
"May",
7+
"June",
8+
"July",
9+
"August",
10+
"September",
11+
"October",
12+
"November",
13+
"December"
14+
]
15+
16+
while True:
17+
try:
18+
inpt= input('Date: ')
19+
if inpt[0].isalpha():
20+
date = inpt.split()
21+
# put input into list
22+
if ',' not in date[1]:
23+
raise Exception
24+
date[1]= date[1].replace(',','')
25+
# check valid month
26+
if date[0] not in month:
27+
raise Exception
28+
if int(date[1]) > 31:
29+
raise Exception
30+
date_type = 1
31+
break
32+
else:
33+
date = inpt.split('/')
34+
# check valid date and month
35+
if int(date[0]) > 12 or int(date[1]) > 31:
36+
raise Exception
37+
date_type = 2
38+
break
39+
except:
40+
pass
41+
elif date_type == 1:
42+
month_no = str(month.index(date[0])+1)
43+
print(date[2].zfill(4), month_no.zfill(2), date[1].zfill(2), sep='-')
44+
45+
elif date_type == 2:
46+
print(date[2].zfill(4), date[0].zfill(2), date[1].zfill(2), sep='-')

pset3/taqueria.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
menu = {
2+
"Baja Taco": 4.00,
3+
"Burrito": 7.50,
4+
"Bowl": 8.50,
5+
"Nachos": 11.00,
6+
"Quesadilla": 8.50,
7+
"Super Burrito": 8.50,
8+
"Super Quesadilla": 9.50,
9+
"Taco": 3.00,
10+
"Tortilla Salad": 8.00
11+
}
12+
total = 0
13+
14+
while True:
15+
try:
16+
item = input('Item: ').lower().title()
17+
if item not in menu:
18+
raise Exception
19+
except EOFError:
20+
break
21+
except:
22+
continue
23+
else:
24+
total += menu[item]
25+
print(f'Total :${total:.2f}')

0 commit comments

Comments
 (0)