Best Python code snippet using lisa_python
itt_student_practice.py
Source:itt_student_practice.py
1import json2def search_word_1st(get_information, search, main_key):3 find_list=[]4 for num in range(0, len(get_information)):5 for find_key,find_value in get_information[num].items():6 if search in find_value:7 if main_key==find_key:8 find_list.append([num, find_key, find_value])9 return find_list10def search_word_2nd(get_information, search, main_key, second_key):11 find_list=[]12 for num in range(0, len(get_information)):13 for find_key, find_value in get_information[num][main_key].items():14 if search==find_value:15 if second_key==find_key:16 find_list.append([num, find_key, find_value])17 print(find_value)18 print(find_list)19 return find_list20def search_word_3th(get_information, search, main_key, second_key, third_key):21 find_list=[]22 for num in range(0, len(get_information)):23 for num in range(0, len(get_information[num][main_key][second_key])):24 for find_key, find_value in get_information[num][main_key][second_key][num].items():25 if search in find_value:26 if third_key==find_key:27 find_list.append([num, find_key, find_value])28 return find_list29def search_course_learned(get_information, search, main_key, second_key):30 find_list=[]31 find_list_2=[]32 for num in range(0,len(get_information)):33 if len(get_information[num][main_key][second_key])!=0:34 find_list.append([num, main_key, len(get_information[num][main_key][second_key])])35 elif len(get_information[num][main_key][second_key])==0:36 find_list.append([num, main_key, len(get_information[num][main_key][second_key])])37 if search=='y':38 print_result(get_information, find_list)39 elif search=='n':40 print_result(get_information, find_list_2)41 else:42 search=input("'y' or 'n' ì¼ë¡ ì
ë ¥í´ì£¼ì¸ì: ")43 search_course_learned(get_information, search, main_key, second_key)44def print_result(get_information, find_list):45 if len(find_list)==1:46 num=find_list[0][0]47 print("* ID: %s"%get_information[num]['student_ID'])48 print("* ì´ë¦: %s"%get_information[num]['student_name'])49 print("* ëì´: %s"%get_information[num]['student_age'])50 print("* 주ì: %s"%get_information[num]['address'])51 print("* ìê° ì ë³´")52 print(" + 과거 ìê° íì: %s"%get_information[num]['total_course_info']['num_of_course_learned'])53 print(" + íì¬ ìê° ê³¼ëª©: ")54 for count in range(len(get_information[num]['total_course_info']['learning_course_info'])):55 print(" %s)"%(count+1))56 print(" ê°ì ì½ë: %s"%get_information[num]['total_course_info']['learning_course_info'][count]['course_code'])57 print(" ê°ìëª
: %s"%get_information[num]['total_course_info']['learning_course_info'][count]['course_name'])58 print(" ê°ì¬: %s"%get_information[num]['total_course_info']['learning_course_info'][count]['teacher'])59 print(" ê°ê°ì¼: %s"%get_information[num]['total_course_info']['learning_course_info'][count]['open_date'])60 print(" ì¢
ë£ì¼: %s"%get_information[num]['total_course_info']['learning_course_info'][count]['close_date'])61 elif len(find_list)==0:62 pass63 else:64 print(" ----- ìì½ ê²°ê³¼ ----- ")65 for num in range(0,len(find_list)):66 print("íì ID: %s, íì ì´ë¦: %s"%(get_information[num]['student_ID'],get_information[num]['student_name']))67def insert_information(get_information):68 file_data_list=[]69 global file_data70 while True:71 file_data={}72 count=len(get_information)73 file_data['student_ID'] = ("ITT{0:0>3}".format(count+1))74 file_data['student_name'] = input("ì´ë¦ (ì: í길ë): ")75 file_data['student_age'] = input("ëì´ (ì: 29): ")76 file_data['address'] = input("주ì (ì: ë구ê´ìì ë구 ììë¡ 135): ")77 num_of_course_learned=input("과거 ìê° íì ( ì: 1): ")78 now_learn=input("íì¬ ìê°íë ê³¼ëª©ì´ ììµëê¹? (ì: y/n): ")79 learning_course_info=[]80 while True:81 if now_learn=='y':82 course_code=input("ê°ìì½ë (ì: IB171106, OB0104 ..): ")83 course_name=input("ê°ìëª
(ì: IOT ë¹
ë°ì´í° ì¤ë¬´ë°): ")84 teacher=input("ê°ì¬ (ì: ì´í구): ")85 open_date=input("ê°ê°ì¼ (ì: 2017-11-06): ")86 close_date=input("ì¢
ë£ì¼ (ì: 2018-09-05): ")87 learning_course_info.append({'course_code':course_code,'course_name':course_name,'teacher':teacher,'open_date':open_date,'close_date':close_date,})88 now_learn=input("íì¬ ìê°íë ê³¼ëª©ì´ ë ììµëê¹? (ì: y/n): ")89 elif now_learn=='n':90 if len(learning_course_info)==0:91 learning_course_info.append({})92 break93 else:94 now_learn=input("'y' or 'n' ì¼ë¡ ì
ë ¥í´ì£¼ì¸ì: ")95 file_data['total_course_info']={'learning_course_info':learning_course_info,'num_of_course_learned':num_of_course_learned}96 file_data_list.append(file_data)97 get_information=file_data_list98 print(file_data_list)99 insert_continue=input("íì ì 보를 ë ì
ë ¥íìê² ìµëê¹? (y/n): ")100 if insert_continue=='n':101 break102 print(file_data_list)103 print(get_information)104 return get_information105def select_information(get_information):106 print("ìë ë©ë´ë¥¼ ì ííì¸ì.\n1. ì ì²´ íìì ë³´ ì¡°í\nê²ì ì¡°ê±´ ì í\n2. ID ê²ì\n3. ì´ë¦ ê²ì\n4. ëì´ ê²ì\n5. 주ì ê²ì\n6. 과거 ìê° íì ê²ì\n7. íì¬ ê°ì를 ìê°ì¤ì¸ íì\n8. íì¬ ìê° ì¤ì¸ ê°ìëª
\n9. íì¬ ìê° ê°ì¬\n10. ì´ì ë©ë´\n")107 select_num=input("ë©ë´ë¥¼ ì ííì¸ì: ")108 main_key=''109 second_key='learning_course_info'110 if select_num=='1':111 for num in range(len(get_information)):112 print("íì ID: %s, íì ì´ë¦: %s"%(get_information[num]['student_ID'],get_information[num]['student_name']))113 main()114 elif select_num=='10':115 main()116 elif select_num=='7':117 main_key='total_course_info'118 search=input("ê²ìì´ë¥¼ ì
ë ¥íì¸ì (y/n ë¡ ì
ë ¥íì¸ì.): ")119 search_course_learned(get_information, search, main_key, second_key)120 main()121 search=input("ê²ìì´ë¥¼ ì
ë ¥íì¸ì: ")122 third_key='teacher'123 if select_num=='2':124 main_key='student_ID'125 elif select_num=='3':126 main_key='student_name'127 elif select_num=='4':128 main_key='student_age'129 elif select_num=='5':130 main_key='address'131 print_result(get_information, search_word_1st(get_information, search, main_key))132 main_key='total_course_info'133 if select_num=='6':134 second_key='num_of_course_learned'135 print_result(get_information, search_word_2nd(get_information, search, main_key, second_key))136 elif select_num=='9':137 print_result(get_information, search_word_3th(get_information, search, main_key, second_key, third_key))138 elif select_num=='8':139 third_key='course_code'140 find_list=search_word_3th(get_information, search, main_key, second_key, third_key)141 if len(find_list)>0:142 print_result(get_information, find_list)143 else:144 third_key='course_name'145 find_list_2=search_word_3th(get_information, search, main_key, second_key, third_key)146 print_result(get_information, find_list_2)147def update_search(get_information, ):148 search=input("ì 보를 ìì í íìì ID를 ì
ë ¥í´ì£¼ì¸ì. : ")149 find_list=search_word_1st(get_information, search, 'student_ID')150 print_result(get_information, find_list)151 return find_list152def update_main_key(get_information, find_list, main_key):153 print("íì¬ ê°: %s"%get_information[find_list[0][0]][main_key])154 get_information[find_list[0][0]][main_key]=input("ë°ê¾¸ì¤ ê°ì ì
ë ¥íì¸ì. :")155def update_2nd_key(get_information, find_list, second_key):156 print("íì¬ ê°: %s"%get_information[find_list[0][0]]['total_course_info'][second_key])157 get_information[find_list[0][0]]['total_course_info'][second_key]=input("ë°ê¾¸ì¤ ê°ì ì
ë ¥íì¸ì. :")158def update_3th_key(get_information, find_list, third_key):159 if len(get_information[find_list[0][0]]['total_course_info']['learning_course_info'])==1:160 print("ìê°ê³¼ëª© íì¬ ê°: %s"%(get_information[find_list[0][0]]['total_course_info']['learning_course_info'][0][third_key]))161 get_information[find_list[0][0]]['total_course_info']['learning_course_info'][0][third_key]=input("ë°ê¾¸ì¤ ê°ì ì
ë ¥íì¸ì. :")162 elif len(get_information[find_list[0][0]]['total_course_info']['learning_course_info'])>1:163 update_code=input("ìì í ë´ì©ì ìê°ê³¼ëª© ì½ë를 ì
ë ¥í´ ì£¼ì¸ì. :")164 for num in range(0,len(get_information[find_list[0][0]]['total_course_info']['learning_course_info'])):165 for find_key, find_value in get_information[find_list[0][0]]['total_course_info']['learning_course_info'][num].items():166 if find_key=='course_code':167 if find_value==update_code:168 print("%s) ìê°ê³¼ëª© íì¬ ê°: %s"%(num,get_information[find_list[0][0]]['total_course_info']['learning_course_info'][num][third_key]))169 get_information[num]['total_course_info']['learning_course_info'][num][third_key]=input("ë°ê¾¸ì¤ ê°ì ì
ë ¥íì¸ì. :")170def update_information(get_information):171 find_list=update_search(get_information)172 while len(find_list)!=1:173 find_list=update_search(get_information)174 update_num=input("ìì í í목ì ì ííì¸ì.\n1. íì ì´ë¦\n2. ëì´\n3. 주ì\n4. 과거 ìê° íì\n5. íì¬ ìê° ì¤ì¸ ê°ì ì ë³´\n0. ì´ì ë©ë´\në©ë´ ë²í¸ë¥¼ ì
ë ¥íì¸ì: ")175 if update_num=='1':176 update_main_key(get_information, find_list, 'student_ID')177 elif update_num=='2':178 update_main_key(get_information, find_list, 'student_age')179 elif update_num=='3':180 update_main_key(get_information, find_list, 'address')181 elif update_num=='4':182 update_2nd_key(get_information, find_list, 'num_of_course_learned')183 elif update_num=='5':184 update_num_learned_info=input("1. ê°ì ì½ë\n2. ê°ìëª
\n3. ê°ì¬\n4. ê°ê°ì¼\n5. ì¢
ë£ì¼\n0. ì·¨ì\në©ë´ ë²í¸ë¥¼ ì
ë ¥íì¸ì: ")185 if update_num_learned_info=='1':186 update_3th_key(get_information, find_list, 'course_code')187 elif update_num_learned_info=='2':188 update_3th_key(get_information, find_list, 'course_name')189 elif update_num_learned_info=='3':190 update_3th_key(get_information, find_list, 'teacher')191 elif update_num_learned_info=='4':192 update_3th_key(get_information, find_list, 'open_date')193 elif update_num_learned_info=='5':194 update_3th_key(get_information, find_list, 'close_date')195 elif update_num_learned_info=='0':196 pass197 elif update_num=='0':198 main()199def delete_course(get_information, find_list):200 if len(get_information[find_list[0][0]]['total_course_info']['learning_course_info'])==1:201 del get_information[find_list[0][0]]['total_course_info']['learning_course_info'][0]202 elif len(get_information[find_list[0][0]]['total_course_info']['learning_course_info'])>1:203 update_code=input("ìì í ë´ì©ì ìê°ê³¼ëª© ì½ë를 ì
ë ¥í´ ì£¼ì¸ì. :")204 for num in range(0,len(get_information[find_list[0][0]]['total_course_info']['learning_course_info'])):205 for find_key, find_value in get_information[find_list[0][0]]['total_course_info']['learning_course_info'][num].items():206 if find_key=='course_code':207 if find_value==update_code:208 del get_information[find_list[0][0]]['total_course_info']['learning_course_info'][num]209def delete_information(get_information):210 delete_num=input("ìì ì íì ì ííì¸ì.\n1. ì ì²´ ìì \n2. íì¬ ìê° ì¤ì¸ í¹ì 과목ì ë³´ ìì \n3. ì´ì ë©ë´\në©ë´ ë²í¸ë¥¼ ì ííì¸ì: ")211 delete_std=input("ìì í íìì ID를 ì
ë ¥íì¸ì: ")212 find_list=search_word_1st(get_information, delete_std, 'student_ID')213 print(find_list)214 if delete_num=='1':215 del get_information[find_list[0][0]]216 elif delete_num=='2':217 delete_course(get_information,find_list)218 elif delete_num=='3':219 main()220def make_json_file():221 make_order=str(input("íì¼ì ì°¾ì ì ììµëë¤.\n1. íì¼ì ìë¡ ë§ë¤ê² ìµëë¤.\n2. ê²½ë¡ë¥¼ ì
ë ¥íê² ìµëë¤.\n1, 2ë¡ ì ííì¸ì. : "))222 while True:223 if make_order=='1':224 json_file_name=input("íì¼ëª
ì ì
ë ¥í´ì£¼ì¸ì. (ex.ITT_Student.json): ")225 break226 elif make_order=='2':227 json_file_name=input("ê²½ë¡ë¥¼ ì
ë ¥í´ì£¼ì¸ì. (ex.ITT_Student.json): ")228 break229 else:230 make_json_file()231 return json_file_name232def main():233 while True:234 print("\t<< jsonê¸°ë° ì£¼ìë¡ ê´ë¦¬ íë¡ê·¸ë¨ >>\n1. íì ì ë³´ì
ë ¥\n2. íì ì ë³´ì¡°í\n3. íì ì ë³´ìì \n4. íì ì ë³´ìì \n5. íë¡ê·¸ë¨ ì¢
ë£\n")235 select_num=input("ë©ë´ë¥¼ ì ííì¸ì: ")236 if select_num=='1':237 insert_information(get_information)238 print(json.dumps(file_data, ensure_ascii=False, indent="\t"))239 elif select_num=='2':240 select_information(get_information)241 elif select_num=='3':242 update_information(get_information)243 elif select_num=='4':244 delete_information(get_information)245 elif select_num=='5':246 print("íì ì ë³´ ê´ë¦¬ íë¡ê·¸ë¨ì ì¢
ë£í©ëë¤.")247 break248 with open(json_file_name,'w',encoding='UTF8') as file_make:249 file_data_list=json.dumps(file_data, ensure_ascii=False, sort_keys=True, indent=4)250 file_make.write(file_data_list)251try:252 global json_file_name253 json_file_name='ITT_Student.json'254 with open(json_file_name,'r',encoding='utf8') as selection:255 get_info=json.load(selection)256 get_information=get_info257except FileNotFoundError:258 json_file_name=make_json_file()259 get_name=str(json_file_name)260 get_information=[]261 get_information=insert_information(get_information)...
concrete.py
Source:concrete.py
1from abc import ABCMeta2class IConcrete(metaclass=ABCMeta):3 @staticmethod4 def get_information():5 """"The Pizzeria Interface"""6class PipperoniHam(IConcrete):7 def __init__(self):8 self.cheese = 709 self.carbs = 4510 self.fat = 3811 self.protein = 812 def get_information(self):13 return {"cheese": self.cheese, "carbohydrates": self.carbs, "fats": self.fat, "proteins": self.protein}14class Stagioni(IConcrete):15 def __init__(self):16 self.cheese = 3017 self.carbs = 5918 self.fat = 2919 self.protein = 6.320 def get_information(self):21 return {"cheese": self.cheese, "carbohydrates": self.carbs, "fats": self.fat, "proteins": self.protein}22class SpicyHot(IConcrete):23 def __init__(self):24 self.flavour = "hot"25 self.first = "tomato"26 self.second = "ham"27 self.stage = "oliva"28 def get_information(self):29 return {"Number of flavour": self.flavour, "first dish": self.first, "second dish": self.second, "stage": self.stage}30class ConcreteFactory:31 @staticmethod32 def get_information(pizzatype):33 try:34 if pizzatype == "PippetoniHam":35 return PipperoniHam()36 if pizzatype == "Stagioni":37 return Stagioni()38 if pizzatype == "SpicyHot":39 return SpicyHot()40 raise AssertionError("Pizza is lost")41 except AssertionError as _e:42 print(_e)43if __name__ == "__main__":44 PIZZA = ConcreteFactory.get_information("PipperoniHam")45 print("PipperoniHam contains", PIZZA.get_information())46 PIZZA = ConcreteFactory.get_information("Stagioni")47 print("Stagioni Piza contains", PIZZA.get_information())48 PIZZA = ConcreteFactory.get_information("SpicyHot")...
pizzeria.py
Source:pizzeria.py
1from abc import ABCMeta2class Pizza(metaclass=ABCMeta):3 @staticmethod4 def get_information():5 """"The Pizza Interface"""6class PepperoniPizza(Pizza):7 def __init__(self):8 self.cheese = 709 self.carbs = 4510 self.fat = 3811 self.protein = 812 def get_information(self):13 return {"cheese": self.cheese, "carbohydrates": self.carbs, "fats": self.fat, "proteins": self.protein}14class CheesePizza(Pizza):15 def __init__(self):16 self.cheese = 3017 self.carbs = 5918 self.fat = 2919 self.protein = 6.320 def get_information(self):21 return {"cheese": self.cheese, "carbohydrates": self.carbs, "fats": self.fat, "proteins": self.protein}22class SpicyPizza(Pizza):23 def __init__(self):24 self.cheese = 025 self.carbs = 6526 self.fat = 2827 self.protein = 4.328 def get_information(self):29 return {"cheese": self.cheese, "carbohydrates": self.carbs, "fats": self.fat, "proteins": self.protein}30class Pizzeria:31 @staticmethod32 def get_pizza(pizzatype):33 try:34 if pizzatype == "Pepperoni":35 return PepperoniPizza()36 if pizzatype == "Cheese":37 return CheesePizza()38 if pizzatype == "Spicy":39 return SpicyPizza()40 raise AssertionError("Pizza is lost")41 except AssertionError as _e:42 print(_e)43 def get_flyweight(self, param):44 pass45if __name__ == "__main__":46 pizza = Pizzeria.get_pizza("Pepperoni")47 print("Pepperoni Pizza Contains", pizza.get_information())48 pizza = Pizzeria.get_pizza("Cheese")49 print("Cheese Pizza Contains", pizza.get_information())50 pizza = Pizzeria.get_pizza("Spicy")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!