Skip to content

Commit 6b2852b

Browse files
committed
day3
1 parent 8cafc28 commit 6b2852b

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

day1_10+11.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#boolean operation : and ,or ,not
2+
3+
def age_chk(age):
4+
print(f"your {age}")
5+
if age < 18:
6+
print("u cant drink")
7+
elif age == 18:
8+
print("you are new to this")
9+
elif age > 20 and age < 25: # 여러 조건이 포함된 and 연산자
10+
print("you are stil kind of young")
11+
else:
12+
print("u can drink")
13+
14+
age_chk(23)
15+
16+
17+
##########
18+
19+
# for
20+
21+
days = ("mon","tue","wed","thu","fri")
22+
23+
for x in days:
24+
# x는 변수
25+
if x is "wed":
26+
break
27+
else:
28+
print(x)
29+
30+
for y in [1,2,3,4,5]:
31+
print(y)
32+
33+
#파이썬에서는 string도 일종의 배열이므로
34+
for letter in "abafsdgasdg":
35+
print(letter)

homework2.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
"""
2+
Again, the code is broken, you need to create 4 functions.
3+
- add_to_dict: Add a word to a dict.
4+
- get_from_dict: Get a word from inside a dict.
5+
- update_word: Update a word inside of the dict.
6+
- delete_from_dict: Delete a word from the dict.
7+
8+
All this functions should check for errors, follow the comments to see all cases you need to cover.
9+
10+
There should be NO ERRORS from Python in the console.
11+
"""
12+
13+
def add_to_dict(dict, *word): #튜플 형태로 가변 매개변수 받기
14+
if str(type(dict)) == "<class 'dict'>":
15+
if len(word) == 2:
16+
if word[0] in dict:
17+
print(f"{word[0]} is already on the dictionary. Won't add.")
18+
else:
19+
dict[word[0]] = word[1]
20+
print(f"{word[0]} has been added.")
21+
else:
22+
print("You need to send a word and a definition.")
23+
else:
24+
print(f"you need to send a dictionary. You sent: {type(dict)}")
25+
26+
def get_from_dict(dict, *word):
27+
if str(type(dict)) == "<class 'dict'>":
28+
if len(word) == 1:
29+
if word[0] in dict:
30+
print(f"{word[0]}: {dict[word[0]]}")
31+
else:
32+
print(f"{word[0]} was not found in this dict.")
33+
else:
34+
print("You need to send a word to search for.")
35+
else:
36+
print(f"you need to send a dictionary. You sent: {type(dict)}")
37+
38+
def update_word(dict, *word):
39+
if str(type(dict)) == "<class 'dict'>":
40+
if len(word) == 2:
41+
if word[0] in dict:
42+
dict[word[0]] = word[1]
43+
print(f"{word[0]} has been updated to: {word[1]}")
44+
else:
45+
print(f"{word[0]} is not on the dict. Can't update non-existing word.")
46+
else:
47+
print("You need to send a word and a definition to update.")
48+
else:
49+
print(f"you need to send a dictionary. You sent: {type(dict)}")
50+
51+
def delete_from_dict(dict, *word):
52+
if str(type(dict)) == "<class 'dict'>":
53+
if len(word) == 1:
54+
if word[0] in dict:
55+
del dict[word[0]]
56+
print(f"{word[0]} has been deleted.")
57+
else:
58+
print(f"{word[0]} is not on in this dict. Won't delete.")
59+
else:
60+
print("You need to specifty a word to delete.")
61+
else:
62+
print(f"you need to send a dictionary. You sent: {type(dict)}")
63+
64+
# \/\/\/\/\/\/\ DO NOT TOUCH \/\/\/\/\/\/\
65+
66+
import os
67+
68+
os.system('clear')
69+
70+
71+
my_english_dict = {}
72+
73+
print("\n###### add_to_dict ######\n")
74+
75+
# Should not work. First argument should be a dict.
76+
print('add_to_dict("hello", "kimchi"):')
77+
add_to_dict("hello", "kimchi")
78+
79+
# Should not work. Definition is required.
80+
print('\nadd_to_dict(my_english_dict, "kimchi"):')
81+
add_to_dict(my_english_dict, "kimchi")
82+
83+
# Should work.
84+
print('\nadd_to_dict(my_english_dict, "kimchi", "The source of life."):')
85+
add_to_dict(my_english_dict, "kimchi", "The source of life.")
86+
87+
# Should not work. kimchi is already on the dict
88+
print('\nadd_to_dict(my_english_dict, "kimchi", "My fav. food"):')
89+
add_to_dict(my_english_dict, "kimchi", "My fav. food")
90+
91+
92+
print("\n\n###### get_from_dict ######\n")
93+
94+
# Should not work. First argument should be a dict.
95+
print('\nget_from_dict("hello", "kimchi"):')
96+
get_from_dict("hello", "kimchi")
97+
98+
# Should not work. Word to search from is required.
99+
print('\nget_from_dict(my_english_dict):')
100+
get_from_dict(my_english_dict)
101+
102+
# Should not work. Word is not found.
103+
print('\nget_from_dict(my_english_dict, "galbi"):')
104+
get_from_dict(my_english_dict, "galbi")
105+
106+
# Should work and print the definiton of 'kimchi'
107+
print('\nget_from_dict(my_english_dict, "kimchi"):')
108+
get_from_dict(my_english_dict, "kimchi")
109+
110+
print("\n\n###### update_word ######\n")
111+
112+
# Should not work. First argument should be a dict.
113+
print('\nupdate_word("hello", "kimchi"):')
114+
update_word("hello", "kimchi")
115+
116+
# Should not work. Word and definiton are required.
117+
print('\nupdate_word(my_english_dict, "kimchi"):')
118+
update_word(my_english_dict, "kimchi")
119+
120+
# Should not work. Word not found.
121+
print('\nupdate_word(my_english_dict, "galbi", "Love it."):')
122+
update_word(my_english_dict, "galbi", "Love it.")
123+
124+
# Should work.
125+
print('\nupdate_word(my_english_dict, "kimchi", "Food from the gods."):')
126+
update_word(my_english_dict, "kimchi", "Food from the gods.")
127+
128+
# Check the new value.
129+
print('\nget_from_dict(my_english_dict, "kimchi"):')
130+
get_from_dict(my_english_dict, "kimchi")
131+
132+
133+
print("\n\n###### delete_from_dict ######\n")
134+
135+
# Should not work. First argument should be a dict.
136+
print('\ndelete_from_dict("hello", "kimchi"):')
137+
delete_from_dict("hello", "kimchi")
138+
139+
# Should not work. Word to delete is required.
140+
print('\ndelete_from_dict(my_english_dict):')
141+
delete_from_dict(my_english_dict)
142+
143+
# Should not work. Word not found.
144+
print('\ndelete_from_dict(my_english_dict, "galbi"):')
145+
delete_from_dict(my_english_dict, "galbi")
146+
147+
# Should work.
148+
print('\ndelete_from_dict(my_english_dict, "kimchi"):')
149+
delete_from_dict(my_english_dict, "kimchi")
150+
151+
# Check that it does not exist
152+
print('\nget_from_dict(my_english_dict, "kimchi"):')
153+
get_from_dict(my_english_dict, "kimchi")
154+
155+
# \/\/\/\/\/\/\ END DO NOT TOUCH \/\/\/\/\/\/\

0 commit comments

Comments
 (0)