-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
140 lines (96 loc) · 3.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"""
Again, the code is broken, you need to create 4 functions.
- add_to_dict: Add a word to a dict.
- get_from_dict: Get a word from inside a dict.
- update_word: Update a word inside of the dict.
- delete_from_dict: Delete a word from the dict.
All this functions should check for errors, follow the comments to see all cases you need to cover.
There should be NO ERRORS from Python in the console.
"""
# error checker only for add_to_dict func
def check_error_add(a,b,c):
if((a or b or c) == "default"):
return "error_default"
else if(type(a) != dict ):
return "error_dict_type"
else if((type(b) or type(c)) != str):
return "error_str_type"
else if( (b in a) or (c in a ) ):
return "error_conflict_index"
else:
return 0
def add_to_dict(gatcha_dict_1 = "default" , gatcha_index_1 = "default", gatcha_index_2 = "default"):
# the key for error check
key = check_error_add(gatcha_dict_1, gatcha_index_1, gatcha_index_2)
if(key == 0):
pass
else:
def get_from_dict():
pass
def update_word():
pass
def delete_from_dict():
pass
# \/\/\/\/\/\/\ DO NOT TOUCH \/\/\/\/\/\/\
import os
os.system('clear')
my_english_dict = {}
print("\n###### add_to_dict ######\n")
# Should not work. First argument should be a dict.
print('add_to_dict("hello", "kimchi"):')
add_to_dict("hello", "kimchi")
# Should not work. Definition is required.
print('\nadd_to_dict(my_english_dict, "kimchi"):')
add_to_dict(my_english_dict, "kimchi")
# Should work.
print('\nadd_to_dict(my_english_dict, "kimchi", "The source of life."):')
add_to_dict(my_english_dict, "kimchi", "The source of life.")
# Should not work. kimchi is already on the dict
print('\nadd_to_dict(my_english_dict, "kimchi", "My fav. food"):')
add_to_dict(my_english_dict, "kimchi", "My fav. food")
print("\n\n###### get_from_dict ######\n")
# Should not work. First argument should be a dict.
print('\nget_from_dict("hello", "kimchi"):')
get_from_dict("hello", "kimchi")
# Should not work. Word to search from is required.
print('\nget_from_dict(my_english_dict):')
get_from_dict(my_english_dict)
# Should not work. Word is not found.
print('\nget_from_dict(my_english_dict, "galbi"):')
get_from_dict(my_english_dict, "galbi")
# Should work and print the definiton of 'kimchi'
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")
print("\n\n###### update_word ######\n")
# Should not work. First argument should be a dict.
print('\nupdate_word("hello", "kimchi"):')
update_word("hello", "kimchi")
# Should not work. Word and definiton are required.
print('\nupdate_word(my_english_dict, "kimchi"):')
update_word(my_english_dict, "kimchi")
# Should not work. Word not found.
print('\nupdate_word(my_english_dict, "galbi", "Love it."):')
update_word(my_english_dict, "galbi", "Love it.")
# Should work.
print('\nupdate_word(my_english_dict, "kimchi", "Food from the gods."):')
update_word(my_english_dict, "kimchi", "Food from the gods.")
# Check the new value.
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")
print("\n\n###### delete_from_dict ######\n")
# Should not work. First argument should be a dict.
print('\ndelete_from_dict("hello", "kimchi"):')
delete_from_dict("hello", "kimchi")
# Should not work. Word to delete is required.
print('\ndelete_from_dict(my_english_dict):')
delete_from_dict(my_english_dict)
# Should not work. Word not found.
print('\ndelete_from_dict(my_english_dict, "galbi"):')
delete_from_dict(my_english_dict, "galbi")
# Should work.
print('\ndelete_from_dict(my_english_dict, "kimchi"):')
delete_from_dict(my_english_dict, "kimchi")
# Check that it does not exist
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")
# \/\/\/\/\/\/\ END DO NOT TOUCH \/\/\/\/\/\/\