# GenAIEd Python 解答 :::info 此篇筆記為[GenAIEd](https://edaitutor.com/en/course)網站之解答,解答在題目擷圖之下方 由於每個帳號的題目順序不同,此篇筆記以作者帳號之題目順序為主 如有錯誤、不懂、想交流程式、想學 Python 者,請聯繫我 >作者:蔡淳宇 @Chuen666666 >LINE:chuen666666 >Discord:chuen666666 ::: ## Module 1 什麼是「資訊管理」:資訊科技的商管應用 ![image](https://hackmd.io/_uploads/rkt4UHYjkx.png) ```python True ``` ![image](https://hackmd.io/_uploads/S1YUIrKoJx.png) ```python True ``` ## Module 2 Python 程式設計初探 ![image](https://hackmd.io/_uploads/Bk-OUHKo1g.png) ```python True ``` ![image](https://hackmd.io/_uploads/HkrK8HtoJg.png) ```python= x1, y1, x2, y2 = int(input()), int(input()), int(input()), int(input()) print(round(((x2 - x1)**2 + (y2 - y1)**2)**0.5, 1), 7, sep='\n') ``` ![image](https://hackmd.io/_uploads/Hkw9IBtjJg.png) ```python= print(int(input()) * int(input()) // 500) ``` ![image](https://hackmd.io/_uploads/r1mo8rFoyl.png) ```python= print(*divmod(int(input()), 12)) ``` ![image](https://hackmd.io/_uploads/B1rkDHFsyx.png) ```python= d = int(float(input()) * int(input())*24*60*60) print(d, *divmod(d, 150000000), sep='\n') ``` ![image](https://hackmd.io/_uploads/H1uBDHtiye.png) ```python= s = int(input()) m, s = divmod(s, 60) h, m = divmod(m, 60) print(f'{h}:{m}:{s}') ``` ![image](https://hackmd.io/_uploads/ryWPwrYiJx.png) ```python= q, p = int(input()), int(input()) print(f'({p*q}, {p*q*0.1}, {round(p*q*1.1, 5)})') ``` ![image](https://hackmd.io/_uploads/HJYuPrKjyx.png) ```python= print(int((int(input())*int(input())*int(input())*int(input())*0.75)//1000)) ``` ![image](https://hackmd.io/_uploads/S1SYvHYikl.png) ```python= print(int(input()) >= 50, 2, sep='\n') ``` ![image](https://hackmd.io/_uploads/SkYqDHtskg.png) ```python= print(int(input()) * int(input()), 3, sep='\n') ``` ![image](https://hackmd.io/_uploads/ryFjDHKike.png) ```python True ``` ![image](https://hackmd.io/_uploads/BkT2wBYi1l.png) ```python False ``` ![image](https://hackmd.io/_uploads/r1qpvHtjkl.png) ```python False ``` ![image](https://hackmd.io/_uploads/HJtAPHFjyg.png) ```python False ``` ![image](https://hackmd.io/_uploads/r1ueOSKsyx.png) ```python True ``` ![image](https://hackmd.io/_uploads/SkOWuSYjJx.png) ```python False ``` ![image](https://hackmd.io/_uploads/HJWMuBKjJg.png) ```python True ``` ![image](https://hackmd.io/_uploads/BJqSurFo1e.png) ```python True ``` ![image](https://hackmd.io/_uploads/B1d8_Htoyg.png) ```python False ``` ![image](https://hackmd.io/_uploads/rJwvOHKs1l.png) ```python= p, i, n = int(input()), int(input()), int(input()) print(int(p*(1+i/100)**n)) ``` ![image](https://hackmd.io/_uploads/ryQduBFsye.png) ```python= print(int(input())*int(input())+50) ``` ![image](https://hackmd.io/_uploads/H1pKOHFiyl.png) ```python= a, b, c = int(input()), int(input()), int(input()) print((a*3+b*2)//100+(a*2+c)//150+(b*5+c*4)//200) ``` ![image](https://hackmd.io/_uploads/H1T9_BYoJe.png) ```python= print(int(input()) * float(input())) ``` ![image](https://hackmd.io/_uploads/r12iOHFske.png) ```python= print(int(input()) > int(input()), 3, sep='\n') ``` ![image](https://hackmd.io/_uploads/Skw2urFjkg.png) ```python= print(int(input()) * float(input())) ``` ![image](https://hackmd.io/_uploads/SkZaurKs1g.png) ```python= print(float(input())*12 + float(input())*1.5) ``` ![image](https://hackmd.io/_uploads/Sk66OBtj1x.png) ```python= print(int(((4/3)*3.14*float(input())**3) * int(input()))) ``` ![image](https://hackmd.io/_uploads/rkdROStjyl.png) ```python= print(abs(100 - int(input()))) ``` ![image](https://hackmd.io/_uploads/HyO1KSKsJl.png) ```python= print(int(input()) * int(input()), 3, sep='\n') ``` ![image](https://hackmd.io/_uploads/BJQeFSFske.png) ```python= print(int(input()) ** 2) ``` ![image](https://hackmd.io/_uploads/Hy--FHKi1l.png) ```python= print(int(input()) + int(input())) ``` ![image](https://hackmd.io/_uploads/ByT-YBFiJe.png) ```python= print(int(input())*int(input()) + int(input())*int(input()), 6, sep='\n') ``` ![image](https://hackmd.io/_uploads/HydMKSFokl.png) ```python= total = 0 for _ in range(7): total += int(input()) print(total, 8, sep='\n') ``` ![image](https://hackmd.io/_uploads/SJuXFrYokg.png) ```python= print(int(input()) + int(input())) ``` ![image](https://hackmd.io/_uploads/HJzNtBtskx.png) ```python= print(int(input()) + int(input())) ``` ![image](https://hackmd.io/_uploads/Sk7BtrFoye.png) ```python= a, b = int(input()), int(input()) print(a+b, a-b, a*b, a//b, a%b, a**b, sep='\n') ``` ![image](https://hackmd.io/_uploads/SJZIKHFi1x.png) ```python= print(int(input()) + int(input()) + int(input()), 4, sep='\n') ``` ![image](https://hackmd.io/_uploads/r1WPKrKikl.png) ```python= print(round((int(input())+int(input())) * (1+int(input())/100), 1), 4, sep='\n') ``` ![image](https://hackmd.io/_uploads/rJ3PYHFiyl.png) ```python= print(int(input()) * int(input())) ``` ![image](https://hackmd.io/_uploads/HkDOtHKj1g.png) ```python= print((int(input())*int(input()) + int(input())*int(input())) * 120, 5, sep='\n') ``` ## Module 3 「電腦運作基本原理」與「條件式選擇」(一) ![image](https://hackmd.io/_uploads/rJzjirFjyl.png) ```python True ``` ![image](https://hackmd.io/_uploads/rkMhoSYo1x.png) ```python= m, p, d = input(), float(input()), input() dis = p * 0.7 if m=='Gold' else p * 0.8 if m=='Silver' else p if d == 'YES': dis *= 0.9 print(max(dis, p*0.6), 13, sep='\n') ``` ![image](https://hackmd.io/_uploads/ryzToHKj1g.png) ```python= age, income, is_emp = int(input()), float(input()), input() print('Loan Approved' if age>=21 and income>=30000 and is_emp=='employed' else 'Loan Denied') ``` ![image](https://hackmd.io/_uploads/rkwAorFikl.png) ```python= temp, home, time = float(input()), input(), input() if temp < 20: if home == 'False': print('Away Heating') else: print('Eco Heating' if time=='night' else 'Comfort Heating') elif temp > 25: print('Cooling') else: print('Off') ``` ![image](https://hackmd.io/_uploads/SkaJhBKike.png) ```python= n, s = float(input()), input() if s == '+': print(n * 2) elif s == '-': print(0.0) elif s == '*': print(n**2) elif s == '/': print(1.0 if n!=0 else 'inf') else: print(0.0) ``` ![image](https://hackmd.io/_uploads/HJhenrts1e.png) ```python= tp = input() print(4200.0 if tp=='Manager' else 3605.0 if tp=='Developer' else 2000.0 if tp=='Intern' else 0.0) ``` ![image](https://hackmd.io/_uploads/S1sWhHYoJx.png) ```python= age, income, mem = int(input()), round(float(input()), 1), input() if age>=18 and income>=50000 and mem=='yes': print('Eligible for Premium Account') elif age>=18 and income>=30000: print('Eligible for Standard Account') else: print('Not eligible for any account') ``` ![image](https://hackmd.io/_uploads/H1wfnrti1l.png) ```python= gpa, sco, now = float(input()), int(input()), input() if gpa>=3.5 and sco>=90: print('Premium Housing' if now=='True' else 'Standard Housing') elif gpa>=3 and sco>=60: print('Economy Housing') else: print('On-Campus Residence') ``` ![image](https://hackmd.io/_uploads/Hym73rtsJg.png) ```python= score, day = float(input()), int(input()) print(1000 if score>=4.5 and day>=250 else 500 if score>=4 and day>=200 else 0) ``` ![image](https://hackmd.io/_uploads/BkrVhrtoyx.png) ```python= print('Yes' if input()=='5' else 'No', 3, sep='\n') ``` ![image](https://hackmd.io/_uploads/SyRVnHKike.png) ```python True ``` ![image](https://hackmd.io/_uploads/B1ir3HFokx.png) ```python True ``` ![image](https://hackmd.io/_uploads/B1P8nBYikg.png) ```python False ``` ![image](https://hackmd.io/_uploads/ryyDnHtsJl.png) ```python False ``` ![image](https://hackmd.io/_uploads/Hy3v2BFiye.png) ```python True ``` ![image](https://hackmd.io/_uploads/B19dhBYi1e.png) ```python False ``` ![image](https://hackmd.io/_uploads/S1vFnBKj1l.png) ```python False ``` ![image](https://hackmd.io/_uploads/rkr93Btiyx.png) ```python False ``` ![image](https://hackmd.io/_uploads/SyT9nSYj1x.png) ```python True ``` ![image](https://hackmd.io/_uploads/rywsnHtjyx.png) ```python= month = int(input()) print('Winter' if month in (12, 1, 2) else 'Spring' if month in (3, 4, 5) else 'Summer' if month in (6, 7, 8) else 'Fall' if month in (9, 10, 11) else 'Invalid month', 2, sep='\n') ``` ![image](https://hackmd.io/_uploads/S1rh2Sti1l.png) ```python= print('Brewing coffee...' if input()=='Coffee' else 'No coffee right now.', 2, sep='\n') ``` ![image](https://hackmd.io/_uploads/SyR33SKi1x.png) ```python= print(float(input())*int(input())+float(input())) ``` ![image](https://hackmd.io/_uploads/rkdpnSKikl.png) ```python= print((100-float(input()))/100 * float(input())) ``` ![image](https://hackmd.io/_uploads/ryM02SYjkg.png) ```python= print(float(input()) + float(input()) + float(input())) ``` ![image](https://hackmd.io/_uploads/rJi0nBYiyl.png) ```python= a = int(input()) print('Negative' if a<0 else 'Positive' if a>0 else 'Zero', 5, sep='\n') ``` ![image](https://hackmd.io/_uploads/rJ7JTBKoyg.png) ```python= print(int(input()) + int(input())) ``` ![image](https://hackmd.io/_uploads/BykepHFs1g.png) ```python= role, salary, years, rating = input(), float(input()), int(input()), input() if role == 'Manager': bonus = 2000 if rating=='excellent' else 1500 if rating=='good' and years>=10 else 1000 else: bonus = salary*0.2 if rating=='excellent' and years>=5 else salary*0.1 if rating=='good' and years>=3 else 0 print(int(bonus), 8, sep='\n') ``` ![image](https://hackmd.io/_uploads/HkjgTHto1l.png) ```python= print(round(int(input())+float(input()), 1)) ``` ![image](https://hackmd.io/_uploads/ryQW6Sto1l.png) ```python= residency, income = input(), float(input()) if residency == 'yes': tax_rate = 30 if income>100000 else 20 else: tax_rate = 40 if income>100000 else 30 print(tax_rate, 5, sep='\n') ``` ![image](https://hackmd.io/_uploads/S16WaBtsJx.png) ```python= print(int(input())>=18 and int(input())>=5) ``` ![image](https://hackmd.io/_uploads/SyBGaSYjkx.png) ```python= print(f'Account Number: {input()}, Balance: ${int(float(input()))}') ``` ![image](https://hackmd.io/_uploads/ryx7aBYokg.png) ```python= print(round(float(input())*(1+float(input())), 1)) ``` ![image](https://hackmd.io/_uploads/HkS4aSKoyg.png) ```python= age, inc = int(input()), int(input()) print('Eligible for loan' if age>=18 and inc>=30000 else 'Not eligible due to age' if age < 18 else 'Not eligible due to income') ``` ![image](https://hackmd.io/_uploads/HyCGMOFoyg.png) ```python= n = int(input()) print(f'Double is {n*2}\n{"It is zero." if n==0 else "Not zero."}\n4') ``` ![image](https://hackmd.io/_uploads/S1I7fuYiyx.png) ```python= m = float(input()) print(m*0.9 if m>500 else m*0.95) ``` ![image](https://hackmd.io/_uploads/SkJ4MuKjJg.png) ```python= print(int(float(input()))) ``` ![image](https://hackmd.io/_uploads/rJJSMutoJg.png) ```python= p = float(input()) * int(input()) print(round(p*0.9 if p>100 else p, 1)) ``` ![image](https://hackmd.io/_uploads/ByurMdtjJl.png) ```python= print(float(input()+input())) ``` ![image](https://hackmd.io/_uploads/S1-IGuKs1l.png) ```python= h, r, i = int(input()), float(input()), input() pay = h * r if h <= 40 else 40 * r + (h-40) * 1.5 * r if i == 'Y': pay *= 0.8 print(f'Final Pay: {pay}\n11') ``` ![image](https://hackmd.io/_uploads/S1RIzutokg.png) ```python= r, d, m = float(input()), int(input()), input() b = d * r if m == 'Y': b *= 0.9 print(f'Final Cost: {b}\n7') ``` ## 作業一 (3/9 11:59pm 截止) ### 第一題 ```python= x, y = int(input()), int(input()) ans = (x*12+y) * 2.5 print(f'{int(ans*10)},{int(ans)}') ``` ## Module 4「電腦運作基本原理」與「條件式選擇」(二) ![image](https://hackmd.io/_uploads/BkoGGRKi1x.png) ```python True ``` ![image](https://hackmd.io/_uploads/S1EQGRtikl.png) ```python= c = float(input()) r = 0.1 if c<=100 else 0.12 if c<=300 else 0.15 if c<=500 else 0.2 print(f'Total electricity bill: ${c*r:.2f}\n2') ``` ![image](https://hackmd.io/_uploads/BJRmzRKo1x.png) ```python= amm, saf = int(input()), int(input()) print('需要緊急補貨' if amm<saf/2 else '需要補貨' if amm<saf else '不需要補貨') ``` ![image](https://hackmd.io/_uploads/HkdVG0Kjyl.png) ```python= age = int(input()) print('可以投票' if age >= 20 else f'還需{20-age}年才可以投票') ``` ![image](https://hackmd.io/_uploads/r1eBzRYjyl.png) ```python= a = [int(input()) for i in range(3)] a.sort() if a[0]**2 + a[1]**2 != a[2]**2: print('不', end='') print('符合畢氏定理') ``` ![image](https://hackmd.io/_uploads/BJqwzCFsJg.png) ```python= a, b, c = float(input()), float(input()), float(input()) m = a * b * (100-c) / 100 print('無銷售' if m==0 else '銷售金額不足' if m<5000 else '銷售金額達標' if m<20000 else '銷售金額優異', end='') print(',無折扣' if c==0 else ',優惠良好' if c==10 else ',大幅優惠' if c==20 else '') ``` ![image](https://hackmd.io/_uploads/H1BuzCFoke.png) ```python= a, b, c = int(input()), int(input()), int(input()) if a >= b: d = a*0.05 + max((a-b*1.5)*0.02, 0) else: d = a*0.02 if c>5 else 0 print(int(d)) ``` ![image](https://hackmd.io/_uploads/rJLKG0tike.png) ```python= # Get student information student_id = input() # line 1 gpa = float(input()) # line 2 is_honors = input() # line 3 is_probation = input() # line 4 is_international = input() # line 5 prev_grade = input() # line 6 # Get course information course_number = int(input()) # line 7 course_credits = int(input()) # line 8 is_lab = input() # line 9 is_online = input() # line 10 current_credits = int(input()) # line 11 current_labs = int(input()) # line 12 current_online = int(input()) # line 13 # Initialize variables registration_allowed = True # line 14 reasons = [] # line 15 # Check GPA requirements if gpa < 2.0: # line 16 registration_allowed = False # line 17 reasons.append("GPA below 2.0") # line 18 elif course_number >= 3000 and gpa < 2.5: # line 19 registration_allowed = False # line 20 reasons.append("GPA below 2.5 for advanced course") # line 21 elif course_number >= 4000 and gpa < 3.5: # line 22 registration_allowed = False # line 23 reasons.append("GPA below 3.5 for honors course") # line 24 # Check credit limits max_credits = 18 # line 25 if is_honors == "y": # line 26 max_credits = 21 # line 27 elif is_probation == "y": # line 28 max_credits = 13 # line 29 if current_credits + course_credits < 12: # line 30 registration_allowed = False # line 31 reasons.append("Below minimum credits") # line 32 elif current_credits + course_credits > max_credits: # line 33 registration_allowed = False # line 34 reasons.append("Exceeds maximum credits") # line 35 # Check lab and online course limits if is_lab == "y" and current_labs + 1 > 2: # line 36 registration_allowed = False # line 37 reasons.append("Exceeds lab course limit") # line 38 if is_online == "y" and current_online + 1 > 3: # line 39 registration_allowed = False # line 40 reasons.append("Exceeds online course limit") # line 41 # Check if retaking passed course if prev_grade in ["A", "B", "C"]: # line 42 registration_allowed = False # line 43 reasons.append("Cannot retake passed course") # line 44 # Calculate tuition if registration allowed if registration_allowed: # line 45 base_tuition = course_credits * 500 # line 46 if is_lab == "y": # line 47 base_tuition += course_credits * 100 # line 48 if is_online == "y": # line 49 base_tuition = base_tuition * 0.90 # line 50 if is_international == "y": # line 51 base_tuition = base_tuition * 1.40 # line 52 print(f"Registration approved\nTuition fee: ${base_tuition:.2f}") # line 53 else: print("Registration denied") # line 55 for reason in reasons: # line 56 print(f"Reason: {reason}") # line 57 print(52) ``` ![image](https://hackmd.io/_uploads/B1l3M0tjkg.png) ```python= # Get booking details venue_type = input() # line 1 num_guests = int(input()) # line 2 start_hour = int(input()) # line 3 duration = int(input()) # line 4 is_weekend = input() # line 5 is_holiday = input() # line 6 # Get catering preferences catering_package = input() # line 7 want_wine = input() # line 8 want_dessert = input() # line 9 want_coffee = input() # line 10 # Validate capacity max_capacity = 0 # line 11 base_rate = 0 # line 12 if venue_type == "small": # line 13 max_capacity = 30 # line 14 base_rate = 200 # line 15 elif venue_type == "medium": # line 16 max_capacity = 100 # line 17 base_rate = 500 # line 18 elif venue_type == "large": # line 19 max_capacity = 300 # line 20 base_rate = 1000 # line 21 else: # grand max_capacity = 500 # line 22 base_rate = 2000 # line 23 if num_guests > max_capacity: # line 24 print("Exceeds venue capacity") # line 25 exit() # line 26 # Calculate time slot adjustment time_multiplier = 1.0 # line 27 if 8 <= start_hour <= 12: # line 28 time_multiplier = 1.0 # line 29 elif 13 <= start_hour <= 17: # line 30 time_multiplier = 1.20 # line 31 elif 18 <= start_hour <= 23: # line 32 time_multiplier = 1.50 # line 33 else: time_multiplier = 1.75 # line 34 # Apply weekend/holiday surcharge if is_holiday == "y": # line 35 time_multiplier += 0.40 # line 36 elif is_weekend == "y": # line 37 time_multiplier += 0.25 # line 38 # Calculate venue cost hourly_rate = base_rate * time_multiplier # line 39 venue_cost = hourly_rate * duration # line 40 # Calculate catering cost catering_base = 0 # line 41 if catering_package == "basic": # line 42 catering_base = 30 # line 43 elif catering_package == "premium": # line 44 catering_base = 50 # line 45 else: # deluxe catering_base = 80 # line 46 # Add catering extras if want_wine == "y": # line 47 catering_base += 15 # line 48 if want_dessert == "y": # line 49 catering_base += 10 # line 50 if want_coffee == "y": # line 51 catering_base += 5 # line 52 catering_cost = catering_base * num_guests # line 53 subtotal = venue_cost + catering_cost # line 54 if duration >= 10: # line 55 subtotal *= 0.80 # line 56 elif duration >= 7: # line 57 subtotal *= 0.85 # line 58 elif duration >= 4: # line 59 subtotal *= 0.90 # line 60 # Print detailed breakdown print(f'''Base venue rate: ${base_rate:.2f}/hour Time slot adjustment: +{(time_multiplier-1)*100:.0f}% Venue cost for {duration} hours: ${venue_cost:.2f} Catering cost for {num_guests} guests: ${catering_cost:.2f}''') if duration >= 4: print(f"Duration discount applied: -{(1-0.90)*100:.0f}%") print(f'''Total cost: ${subtotal:.2f} Cost per person: ${(subtotal/num_guests):.2f} 56''') ``` ![image](https://hackmd.io/_uploads/ryHpG0tiJe.png) ```python= temperature, humidity, wind_speed = float(input()), float(input()), float(input()) if temperature > 30: advisory = 'Hot and Humid, stay indoors' if humidity>70 else 'Hot and Windy' if wind_speed>20 else 'Hot' elif temperature >= 15 and temperature <= 30: advisory = 'Pleasant but Humid' if humidity>70 else 'Pleasant' else: advisory = 'Cold' print(f'Weather Advisory: {advisory}\n6') ``` ![image](https://hackmd.io/_uploads/H110zCKokx.png) ```python True ``` ![image](https://hackmd.io/_uploads/SkDAfAYoyx.png) ```python True ``` ![image](https://hackmd.io/_uploads/Sk-yXAtiJl.png) ```python False ``` ![image](https://hackmd.io/_uploads/rJtJ7Ctjkx.png) ```python False ``` ![image](https://hackmd.io/_uploads/SkwgXRYj1l.png) ```python False ``` ![image](https://hackmd.io/_uploads/SJ4Wm0ti1x.png) ```python True ``` ![image](https://hackmd.io/_uploads/BkyfXCKjJg.png) ```python False ``` ![image](https://hackmd.io/_uploads/B16G70ti1e.png) ```python True ``` ![image](https://hackmd.io/_uploads/rJ2X70Yjyl.png) ```python True ``` ![image](https://hackmd.io/_uploads/B1i4mRKsJl.png) ```python= income = float(input()) tax_rate = 0.1 if 30000>=income>10000 else 0.2 if 100000>=income>30000 else 0.3 if income>100000 else 0 print(f"Tax amount: ${income*tax_rate:.2f}\n2") ``` ![image](https://hackmd.io/_uploads/rkdi7AFoJe.png) ```python= t = int(input()) print('早安' if 0<=t<12 else '午安' if 12<=t<18 else '晚安') ``` ![image](https://hackmd.io/_uploads/ryG2XCtiyg.png) ```python= p = int(input()) print('銷售平平' if p==0 else '穩定增長' if p>0 and p%2==0 else '波動增長' if p>0 else '輕微下滑' if p<0 and p%2==0 else '嚴重下滑', end='') if abs(p) in (100, 200, 300, 500, 800, 1300): print(',關鍵銷售額') ``` ![image](https://hackmd.io/_uploads/BJbaQCYiJe.png) ```python= t = int(input()) print('VIP顧客' if t>=20 else '忠實顧客' if t>=10 else '普通顧客') ``` ![image](https://hackmd.io/_uploads/H1fkNAYoJx.png) ```python= member_type = input() # line 1 book_type = input() # line 2 book_price = float(input()) # line 3 days_overdue = int(input()) # line 4 damage_level = input() # line 5 interlibrary = input() # line 6 holiday = input() # line 7 current_loans = int(input()) # line 8 current_fees = float(input()) # line 9 loan_approved = True # line 10 total_fee = 0 # line 11 overdue_fee = 0 # line 12 damage_fee = 0 # line 13 processing_fee = 0 # line 14 max_loans = 5 if member_type == "student" else 10 if member_type == "faculty" else 3 if current_loans >= max_loans: # line 21 print("Exceeds maximum loans") # line 22 loan_approved = False # line 23 loan_days = 14 if book_type == "regular" else 7 if book_type == "new" else 3 if book_type == "reference" else 30 if holiday == "y": # line 32 loan_days += 7 # line 33 if days_overdue > 0: overdue_fee = days_overdue * 0.5 if book_type == "regular" else days_overdue if book_type == "new" else days_overdue * 2 if book_type == "reference" else days_overdue * 1.5 if damage_level == "minor": # line 43 damage_fee = 10 # line 44 elif damage_level == "major": # line 45 damage_fee = book_price * 0.50 # line 46 elif damage_level == "lost": # line 47 damage_fee = book_price # line 48 processing_fee += 20 # line 49 if interlibrary == "y": # line 50 processing_fee += 5 # line 51 total_fee = overdue_fee + damage_fee + processing_fee # line 52 if current_fees + total_fee > 50: # line 53 print("Total fees would exceed limit") # line 54 loan_approved = False # line 55 if days_overdue > 0: # line 56 print(f"Overdue days: {days_overdue}\nOverdue fee: ${overdue_fee:.2f}") # line 57 if damage_fee > 0: # line 59 print(f"Damage fee: ${damage_fee:.2f}") # line 60 if processing_fee > 0: # line 61 print(f"Processing fee: ${processing_fee:.2f}") # line 62 print(f'Total fee: ${total_fee:.2f}\nLoan {"approved" if loan_approved else "denied"}\n40') ``` ![image](https://hackmd.io/_uploads/rJGgN0Ysye.png) ```python= make, goal = int(input()), int(input()) print('超過目標200%' if make>=goal*2 else '達到目標' if make>=goal else '未達到目標') ``` ![image](https://hackmd.io/_uploads/Bk7-NAFiJg.png) ```python= a ,b, c = int(input()), int(input()), int(input()) inc = a + b + c if c > b: inc *= 1.05 if a < b: inc -= 1000 if inc > 50000: inc += 2000 print(round(inc)) ``` ![image](https://hackmd.io/_uploads/SJWz4AKsJe.png) ```python= sco, sta = int(input()), int(input()) print('達到優秀標準' if sco>=sta*1.2 else '達到標準' if sco>=sta else '未達到標準') ``` ![image](https://hackmd.io/_uploads/H1hfN0Fo1x.png) ```python= s = int(input()) print('優秀' if s>=90 else '高於平均' if s>=70 else '低於平均') ``` ![image](https://hackmd.io/_uploads/Bk57NRFo1g.png) ```python= a, g = int(input()), int(input()) print('超過目標120%' if a>g*1.2 else '達成目標' if a>=g else '未達成目標') ``` ![image](https://hackmd.io/_uploads/Hk8VN0Yiye.png) ```python= a, b = int(input())*int(input()), int(input()) print('達到最低收入標準' if a>=b else '未達到最低收入標準') ``` ![image](https://hackmd.io/_uploads/rk5HN0tjkl.png) ```python= car_type = input() # line 1 age = int(input()) # line 2 accident_count = int(input()) # line 3 location = input() # line 4 collision = input() # line 5 comprehensive = input() # line 6 roadside = input() # line 7 premium = 500 if car_type=='economy' else 700 if car_type=='sedan' else 900 if car_type=='suv' else 1500 if age < 25: # line 15 premium *= 1.5 # line 16 elif age > 60: # line 17 premium *= 1.2 # line 18 if accident_count == 0: # line 19 premium *= 0.9 # line 20 elif accident_count == 1: # line 21 premium *= 1.2 # line 22 elif accident_count >= 2: # line 23 premium *= 1.5 # line 24 if location == "urban": # line 25 premium *= 1.25 # line 26 elif location == "rural": # line 27 premium *= 0.9 # line 28 if collision == "y": # line 29 premium += 200 # line 30 if comprehensive == "y": # line 31 premium += 150 # line 32 if roadside == "y": # line 33 premium += 50 # line 34 print(f"Final insurance premium: ${premium:.2f}\n16") ``` ![image](https://hackmd.io/_uploads/SJvwECYjyl.png) ```python= seat_category = input() # line 1 show_time = int(input()) # line 2 is_weekend = input() # line 3 is_holiday = input() # line 4 num_tickets = int(input()) # line 5 # Get seating preferences row_number = int(input()) # line 6 is_center = input() # line 7 is_corner = input() # line 8 # Get customer information age = int(input()) # line 9 is_student = input() # line 10 is_loyalty = input() # line 11 # Initialize base price base_price = 12 if seat_category == "regular" else 15 if seat_category == "premium" else 20 if seat_category == "vip" else 25 # Apply show time adjustments if show_time < 17: # Matinee # line 19 base_price *= 0.75 # line 20 elif is_weekend == "y" and 18 <= show_time <= 22: # line 21 base_price *= 1.25 # Prime time # line 22 elif show_time >= 22: # line 23 base_price *= 0.85 # Late night # line 24 # Apply holiday surcharge if is_holiday == "y": # line 25 base_price += 3 # line 26 # Apply seating location modifiers if row_number <= 3: # Front rows # line 27 base_price -= 2 # line 28 elif row_number >= 15: # Back rows # line 29 base_price += 1 # line 30 if is_center == "y": # line 31 base_price += 2 # line 32 elif is_corner == "y": # line 33 base_price -= 1 # line 34 # Calculate initial total subtotal = base_price * num_tickets # line 35 # Apply personal discounts (only highest applies) discount = 0 # line 36 if age >= 65: # Senior # line 37 discount = max(discount, 0.30) # line 38 elif age < 12: # Child # line 39 discount = max(discount, 0.25) # line 40 elif is_student == "y": # Student # line 41 discount = max(discount, 0.20) # line 42 # Apply group discount if num_tickets >= 6: # line 43 subtotal *= 0.85 # line 44 # Apply personal discount if discount > 0: # line 45 subtotal *= 1 - discount # line 46 # Apply loyalty discount if is_loyalty == "y": # line 47 subtotal *= 0.90 # line 48 final_price = subtotal # line 49 # Print price breakdown print(f"Base ticket price: ${base_price:.2f}") # line 50 print(f"Number of tickets: {num_tickets}") # line 51 if is_holiday == "y": # line 52 print("Holiday surcharge applied: +$3.00") # line 53 if show_time < 17: # line 54 print("Matinee discount: -25%") # line 55 elif is_weekend == "y" and 18 <= show_time <= 22: # line 56 print("Weekend prime time: +25%") # line 57 elif show_time >= 22: # line 58 print("Late night discount: -15%") # line 59 if discount > 0: # line 60 print(f"Personal discount: -{discount*100:.0f}%") # line 61 if num_tickets >= 6: # line 62 print("Group discount: -15%") # line 63 if is_loyalty == "y": # line 64 print("Loyalty discount: -10%") # line 65 print(f"Final price: ${final_price:.2f}\nPrice per ticket: ${(final_price/num_tickets):.2f}\n20") # line 66 ``` ![image](https://hackmd.io/_uploads/SJFd4AtoJl.png) ```python= gpa, act, inc = float(input()), int(input()), int(input()) m = 0 if gpa<3 else 1000 if gpa<=3.5 else 3000 if gpa<=3.8 else 5000 if inc < 40000: m *= 1.2 if 5>act>=3: m += 500 elif act>=5: m += 1000 print(int(m)) ``` ![image](https://hackmd.io/_uploads/HJN9N0Yskg.png) ```python= # Get membership details membership_type = input() # line 1 contract_months = int(input()) # line 2 is_peak_access = input() # line 3 # Get training package training_sessions = int(input()) # line 4 training_start_month = int(input()) # line 5 # Get additional services wants_locker = input() # line 6 wants_towel = input() # line 7 wants_nutrition = input() # line 8 wants_parking = input() # line 9 # Calculate base membership fee if membership_type == "basic": # line 10 base_fee = 40 # line 11 elif membership_type == "standard": # line 12 base_fee = 60 # line 13 elif membership_type == "premium": # line 14 base_fee = 80 # line 15 else: # VIP base_fee = 120 # line 16 # Apply contract duration discount if contract_months >= 12: # line 17 contract_discount = base_fee * 0.25 # line 18 elif contract_months >= 6: # line 19 contract_discount = base_fee * 0.15 # line 20 elif contract_months >= 3: # line 21 contract_discount = base_fee * 0.10 # line 22 else: contract_discount = 0 # line 23 # Calculate discounted monthly fee monthly_fee = base_fee - contract_discount # line 24 # Apply peak/off-peak adjustment if is_peak_access == "n": # line 25 monthly_fee *= 0.80 # line 26 # Calculate training package cost if training_sessions == 1: # line 27 training_fee = 50 # line 28 elif training_sessions == 5: # line 29 training_fee = 225 # line 30 elif training_sessions == 10: # line 31 training_fee = 400 # line 32 elif training_sessions == 20: # line 33 training_fee = 700 # line 34 # Calculate additional services additional_fees = 0 # line 35 if wants_locker == "y": # line 36 additional_fees += 15 # line 37 if wants_towel == "y": # line 38 additional_fees += 10 # line 39 if wants_nutrition == "y": # line 40 additional_fees += 30 # line 41 if wants_parking == "y": # line 42 additional_fees += 25 # line 43 # Calculate monthly payment total_additional = additional_fees * contract_months # line 44 total_membership = monthly_fee * contract_months # line 45 # Calculate total cost total_cost = total_membership + total_additional + training_fee # line 46 # Format monthly payment plan monthly_payment = total_cost / contract_months # line 47 # Print detailed breakdown print(f"Base membership fee: ${base_fee:.2f}") # line 48 if contract_discount > 0: # line 49 print(f"Contract duration discount: -${contract_discount:.2f}") # line 50 print(f"Monthly membership fee: ${monthly_fee:.2f}") # line 51 if training_sessions > 0: # line 52 print(f"Training package ({training_sessions} sessions): ${training_fee:.2f}") # line 53 if additional_fees > 0: # line 54 print(f"Additional services (monthly): ${additional_fees:.2f}") # line 55 print(f"Total cost: ${total_cost:.2f}\nMonthly payment: ${monthly_payment:.2f}\n34") ``` ![image](https://hackmd.io/_uploads/rkUoNRKo1x.png) ```python= t = float(input()) print('熱' if t>30 else '冷' if t<15 else '涼') ``` ![image](https://hackmd.io/_uploads/H1zn4RFskg.png) ```python= a = int(input()) print('符合退休條件' if a>=30 else '符合晉升條件' if a>=5 else '不符合條件') ``` ![image](https://hackmd.io/_uploads/ry2nEAKoJg.png) ```python= a, b = int(input()), int(input()) print('員工A月薪更高' if a>b else '員工B月薪更高' if a<b else '兩者月薪相等') ``` ![image](https://hackmd.io/_uploads/rkO6V0tj1l.png) ```python= count, score, rate = int(input()), int(input()), int(input()) if count == 0: print('無活動') else: a = 3 if score>=90 else 2 if score>=75 else 1 if rate >= 30: a += 1 a = min(3, a) if rate < 10: a -= 1 a = max(1, a) print('優秀' if a==3 else '良好' if a==2 else '一般') ``` ![image](https://hackmd.io/_uploads/S1CAEAYiyg.png) ```python= a = int(input()) if a == 0: print('零') elif a > 0: print(f'正{"偶" if a%2==0 else "奇"}數') else: print(f'負{"偶" if a%2==0 else "奇"}數') ``` ![image](https://hackmd.io/_uploads/Hy1xHAKske.png) ```python= travel_class = input() # line 1 travel_month = int(input()) # line 2 days_ahead = int(input()) # line 3 loyalty_status = input() # line 4 window_aisle = input() # line 5 extra_legroom = input() # line 6 meal_pref = input() # line 7 insurance = input() # line 8 base_price = 300 if travel_class == "economy" else 450 if travel_class == "premium" else 800 if travel_class == "business" else 1200 seasonal_price = base_price * 1.4 if travel_month in [6, 7, 8, 12] else base_price * 1.2 if travel_month in [4, 5, 9, 10, 11] else base_price booking_discount = seasonal_price * 0.2 if days_ahead > 90 else seasonal_price * 0.15 if days_ahead >= 60 else seasonal_price * 0.1 if days_ahead >= 30 else 0 price_after_booking = seasonal_price - booking_discount # line 28 additional_charges = 0 # line 29 if window_aisle == "y": # line 30 additional_charges += 30 # line 31 if extra_legroom == "y": # line 32 additional_charges += 50 # line 33 if meal_pref == "y": # line 34 additional_charges += 25 # line 35 if insurance == "y": # line 36 additional_charges += 20 # line 37 subtotal = price_after_booking + additional_charges # line 38 loyalty_discount = 0 # line 39 if loyalty_status == "gold": # line 40 loyalty_discount = subtotal * 0.15 # line 41 elif loyalty_status == "silver": # line 42 loyalty_discount = subtotal * 0.10 # line 43 elif loyalty_status == "bronze": # line 44 loyalty_discount = subtotal * 0.05 # line 45 final_price = subtotal - loyalty_discount # line 46 print(f'''Base ticket price: ${base_price:.2f} Seasonal adjusted price: ${seasonal_price:.2f} Advance booking discount: -${booking_discount:.2f} Additional charges: ${additional_charges:.2f}''') if loyalty_discount > 0: # line 51 print(f'Loyalty discount: -${loyalty_discount:.2f}') print(f'Final price: ${final_price:.2f}\n19') ``` ## Module 5 Iteration 迴圈(上) ![image](https://hackmd.io/_uploads/SJWPSRtskg.png) ```python True ``` ![image](https://hackmd.io/_uploads/rJbur0tjkg.png) ```python= total_score, valid_rounds, prev_score, low_streak = 0, 0, None, 0 while True: # line 5 score = int(input()) # line 6 if score == -1: # line 7 break # line 8 if score < 0 or score > 10000: # line 9 print("Invalid") # line 10 continue # line 11 if score == 7777: # line 12 print("Jackpot!") # line 13 continue if prev_score is not None: # line 14 if abs(score - prev_score) > 3000: # line 15 print("Score Discrepancy") # line 16 break # line 17 low_streak += 1 if score < 1000 else -low_streak if low_streak == 3: # line 22 print("Underperform") # line 23 break # line 24 total_score += score # line 25 valid_rounds += 1 # line 26 prev_score = score # line 27 print(f"{total_score/valid_rounds:.1f}") # line 28 print(valid_rounds, 13, sep='\n') ``` ![image](https://hackmd.io/_uploads/Sk2OBCFs1e.png) ```python= t, s = 0, 0 for _ in range(int(input())): i = input() if i == 'X': break if i not in ('A', 'B', 'C', 'D'): continue if i == 'B': s += 5 t += 1 print(f'Total Score: {s}\nValid Responses: {t}') ``` ![image](https://hackmd.io/_uploads/H1PFrCFsJe.png) ```python= it, t = float(input()), 0 for _ in range(int(input())): c = float(input()) if c == 0: break if c < 0 and -c > it: continue it += c t += 1 print(f'Final Balance: {it:.2f}\nValid Transactions: {t}') ``` ![image](https://hackmd.io/_uploads/BJM5rRKiJl.png) ```python= left, count, total = int(input()), 0, 0 for _ in range(int(input())): a = int(input()) if a == 0 or left == 0: break elif a < 0: continue if a > left: a = left print('Workshop full') left -= a count += 1 total += a print(f'Total Registered: {total}\nValid Attempts: {count}') ``` ![image](https://hackmd.io/_uploads/H19qB0KjJe.png) ```python= s = 0 for _ in range(int(input())): s += float(input()) print(s) ``` ![image](https://hackmd.io/_uploads/By7jS0tj1x.png) ```python= total, count = 0, 0 for _ in range(int(input())): t = float(input()) if abs(t) > 50: continue if t == 999: break total += t count += 1 print(f'Average Temperature: {total/count:.1f}' if total else 'No valid data') ``` ![image](https://hackmd.io/_uploads/SypiSRFjJl.png) ```python= p, t = 0, 0 for _ in range(int(input())): a = int(input()) if a < 0: continue elif a == 999: break p += a * 0.5 t += 1 print(f'Total Fine: {p:.2f}\nValid Records: {t}') ``` ![image](https://hackmd.io/_uploads/r1onS0KoJg.png) ```python= total, count = 0, 0 for _ in range(int(input())): a = int(input()) if a < 0: continue elif a == 0: break total += a if a<100 else a*0.9 count += 1 print(f'Total Sales: {round(total)}\nValid Records: {count}') ``` ![image](https://hackmd.io/_uploads/ByoaBAYi1e.png) ```python= running_product, count, prev1, prev2 = 1, 0, 0, 0 while True: # line 5 num = int(input()) # line 6 if num == 0: # line 7 break # line 8 if num < 1 or num > 100: # line 9 print("Invalid") # line 10 continue # line 11 if num % 10 == 0: # line 12 print("Skipped") # line 13 prev2 = 0 # line 14 prev1 -= num # line 15 continue # line 16 running_product *= num # line 17 count += 1 # line 18 if prev2 + prev1 + num == 100: # line 19 print("Sum100") # line 20 break # line 21 prev2 = prev1 # line 22 prev1 = num # line 23 if running_product > 1000: # line 24 print("Limit") # line 25 break # line 26 print(running_product) # line 27 print(f"Total: {count}\n15") ``` ![image](https://hackmd.io/_uploads/H1IJUAFi1x.png) ```python False ``` ![image](https://hackmd.io/_uploads/ByF98AFiyx.png) ```python False ``` ![image](https://hackmd.io/_uploads/H14iIAKsye.png) ```python False ``` ![image](https://hackmd.io/_uploads/rJb3LRYsyl.png) ```python False ``` ![image](https://hackmd.io/_uploads/SJnh8AtjJg.png) ```python False ``` ![image](https://hackmd.io/_uploads/ryrp8CKikg.png) ```python False ``` ![image](https://hackmd.io/_uploads/ByQCIRYjJl.png) ```python True ``` ![image](https://hackmd.io/_uploads/SkaRICFsJl.png) ```python False ``` ![image](https://hackmd.io/_uploads/Byr1DCFjJe.png) ```python False ``` ![image](https://hackmd.io/_uploads/r1zeD0Fiye.png) ```python= n = int(input()) print(n//2 if n%2==0 else n//2+1) ``` ![image](https://hackmd.io/_uploads/HyilwCYjJe.png) ```python= m, t = int(input()), 0 while m >= 50: m -= 50 t += 1 print(m) print(f'Total months: {t}') ``` ![image](https://hackmd.io/_uploads/rJD-PRFske.png) ```python= total, count, fail_streak, prev_score = 0, 0, 0, None while True: # line 5 score = int(input()) # line 6 if score == -1: # line 7 break # line 8 if score < 0 or score > 100: # line 9 print("Invalid") # line 10 continue # line 11 if score == 0: # line 12 print("Absent") # line 13 continue # line 14 if prev_score is not None: # line 15 if abs(score - prev_score) > 50: # line 16 print("Score jump") # line 17 break # line 18 if score < 60: # line 19 fail_streak += 1 # line 20 else: fail_streak = 0 if fail_streak == 3: # line 21 print("At Risk") # line 22 break # line 23 total += score # line 24 count += 1 # line 25 prev_score = score # line 26 print(f"{total/count:.1f}") # line 27 print(count, 20, sep='\n') ``` ![image](https://hackmd.io/_uploads/B1HzwAKsyx.png) ```python= from math import factorial print(factorial(int(input()))) ``` ![image](https://hackmd.io/_uploads/r10GPCtiJg.png) ```python= print(*range(int(input()))[::-1], 'Inventory depleted', sep='\n') ``` ![image](https://hackmd.io/_uploads/S1pQP0Foyg.png) ```python= last_stock = restock_count = 0 while True: # line 3 stock = int(input().strip()) if stock == 0: # line 12 break # line 13 if stock < 1 or stock > 500: # line 14 print("Invalid") # line 15 continue # line 16 if stock % 10 == 0: # line 17 print("Skip") # line 18 continue # line 19 if stock < 20: # line 21 print("Out of Stock") # line 22 elif stock - last_stock >= 50: # line 23 print("Restocked") # line 24 restock_count += 1 # line 25 else: # line 26 print("Stable") # line 27 last_stock = stock print(restock_count, 20, sep='\n') ``` ![image](https://hackmd.io/_uploads/HJFNPRKske.png) ```python= print(int(input()) * 40) ``` ![image](https://hackmd.io/_uploads/B1NBvAtoyg.png) ```python= print(int(input()) * 8) ``` ![image](https://hackmd.io/_uploads/SyeLwCFikx.png) ```python= print(sum(i for i in range(1, int(input())+1) if i%2==0)) ``` ![image](https://hackmd.io/_uploads/Hko8vCFj1l.png) ```python= sum_fives = neg_streak = 0 while True: # line 3 num = int(input()) # line 4 if num == 0: # line 5 break # line 6 if num < -100 or num > 100: # line 7 print("Invalid") # line 8 continue # line 9 if num < 0: # line 10 neg_streak += 1 # line 11 if neg_streak == 3: # line 12 break # line 13 else: # line 14 neg_streak = 0 # line 15 if num % 3 == 0: # line 16 print("Skipped") # line 17 continue # line 18 if num % 5 == 0: # line 19 sum_fives += num # line 20 print(f"Sum: {sum_fives}") # line 21 print(f"Total: {sum_fives}\n13") ``` ![image](https://hackmd.io/_uploads/HJLDPCFoJx.png) ```python= for i in range(int(input()), 0, -1): print(i if i%3 else 'Boom!') print('Blast off!') ``` ![image](https://hackmd.io/_uploads/r1WdDAKikl.png) ```python= t = 0 while True: a = input().upper() if a == '#': break if a in ('A', 'E', 'I', 'O', 'U'): t += 1 print(t) ``` ![image](https://hackmd.io/_uploads/HyytDCFiJx.png) ```python= total_time = 0 session_count = 0 long_streak = 0 while True: minutes = int(input()) # line 1 if minutes == -1: # line 2 break # line 3 if minutes < 0 or minutes > 300: # line 4 print("Invalid") # line 5 continue # line 6 if minutes < 30: # line 7 print("Too short") # line 8 continue # line 9 # Process valid session if minutes == 60: # line 10 minutes *= 2 # line 11 session_count += 1 # line 12 if session_count % 3 == 0: # line 13 minutes += 10 # line 14 if minutes > 120: # line 15 long_streak += 1 # line 16 else: long_streak = 0 # line 17 if long_streak == 3: # line 18 print(total_time) # line 19 break # line 20 total_time += minutes # line 21 if total_time > 600: # line 22 print(total_time) # line 23 break # line 24 print(total_time) # line 25 print(session_count, 9, sep='\n') ``` ![image](https://hackmd.io/_uploads/SJTtDAKskl.png) ```python= total_sales, order_count, prev_order, low_count = 0, 0, None, 0 while True: # line 5 order = int(input()) # line 6 if order == -1: # line 7 break # line 8 if order < 1 or order > 200: # line 9 print("Invalid") # line 10 continue # line 11 if order == 50: # line 12 print("Half-Price Special") # line 13 continue # line 14 if prev_order is not None: # line 15 if abs(order - prev_order) > 100: # line 16 print("Price Surge") # line 17 break # line 18 if order < 20: # line 19 low_count += 1 # line 20 else: low_count = 0 if low_count == 3: # line 21 print("Low Sales") # line 22 break # line 23 total_sales += order # line 24 order_count += 1 # line 25 prev_order = order # line 26 print(round(total_sales/order_count, 1)) # line 27 print(order_count, 20, sep='\n') # line 30 ``` ![image](https://hackmd.io/_uploads/rkd5PRFoJe.png) ```python= n = int(input()) print(n//5 if n%5==0 else n//5+1) ``` ![image](https://hackmd.io/_uploads/Sk-iwRFi1e.png) ```python= a = divmod(int(input()), 4) print(f'Complete groups: {a[0]}\nRemaining students: {a[1]}') ``` ![image](https://hackmd.io/_uploads/Hy5svCYsyg.png) ```python= n = int(input()) print((n+1)*n // 2) ``` ![image](https://hackmd.io/_uploads/B1H2v0FiJg.png) ```python= print(int(input()) * 5) ``` ![image](https://hackmd.io/_uploads/Sy3wjCFoyl.png) ```python= t = c = 0 for i in range(1, int(input())+1): a = i*4 - 5 if a < 0: continue elif a == 0: break t += a c += 1 print(f'{t}\n{t/c:.1f}' if t else 'No valid data') ``` ![image](https://hackmd.io/_uploads/rkM5jCKo1x.png) ```python= for i in range(int(input()), 0, -1): print(i) print('Liftoff!') ``` ![image](https://hackmd.io/_uploads/BJljj0Ys1x.png) ```python= i, t = int(input()), 0 while i >= 50: i -= 50 t += 1 print(i) print(f'Total months: {t}') ``` ## 作業二(只有一題)(3/23 11:59pm截止) ### 第一題 ```python= print('Yes' if (float(input())*12+float(input()))*2.5 > float(input()) else 'No') ``` ## Module 6 Iteration 迴圈(下) ![image](https://hackmd.io/_uploads/Sk3B30KiJe.png) ```python False ``` ![image](https://hackmd.io/_uploads/SyB40RFsJx.png) ```python= reps, weeks = int(input()), int(input()) rep1_week1, rep1_week2, rep2_week1, rep2_week2 = int(input()), int(input()), int(input()), int(input()) total_earnings = 0 for i in range(reps): rep_total = 0 for j in range(weeks): if i == 0: if j == 0: earning = rep1_week1 elif j == 1: earning = rep1_week2 else: if j == 0: earning = rep2_week1 elif j == 1: earning = rep2_week2 rep_total += earning total_earnings += earning print(rep_total) print(f"Total Earnings: {total_earnings}\n8") ``` ![image](https://hackmd.io/_uploads/B1F8ARYs1x.png) ```python= n = 0 for i in range(1, int(input())+1): n += i * 80 print(n) ``` ![image](https://hackmd.io/_uploads/ryla00Kjkg.png) ```python= n = int(input()) for i in range(n): print('*'*n if i==0 or i==n-1 else '*'+' '*(n-2)+'*') ``` ![image](https://hackmd.io/_uploads/H1TvBJ9skl.png) ```python= n = 0 for i in range(1, int(input())+1): for j in range(1, 8): hr = i*j%8 + 1 if hr < 4: hr += 1 n += hr print(n) ``` ![image](https://hackmd.io/_uploads/Hki8IJ5oye.png) ```python= a, b = int(input()), int(input()) t = 0 for s in range(1, a+1): for r in range(1, b+1): t += s*r + (10 if r%2 else 15) print(t) ``` ![image](https://hackmd.io/_uploads/rkZtvJ9oyg.png) ```python= l, s, t = int(input()), int(input()), 0 for i in range(l): for j in range(1, s+1): a = 5 + i*2 if j % 2: a -= 1 t += max(1, a) print(t) ``` ![image](https://hackmd.io/_uploads/ByaWPwqsye.png) ```python= cla, stu, tt = int(input()), int(input()), 0 for c in range(cla): t = 0 for s in range(stu): a = int(input()) if a: t += 1 tt += 1 print(t) print(f'Total Attendance: {tt}\n14') ``` ![image](https://hackmd.io/_uploads/B1GJQd9oyg.png) ```python= d = int(input()) #line1 day = 1 #line2 overall_hot = overall_cold = overall_total = overall_valid = 0 while day <= d: #line7 period, day_total, day_valid, all_zero = 1, 0, 0, True while period <= 3: #line13 temp = int(input()) #line14 period += 1 #line15 if temp < -50 or temp > 50: #line16 continue #line17 if temp != 0: #line18 all_zero = False #line19 day_total += temp #line20 day_valid += 1 #line21 if temp >= 30: #line22 overall_hot += 1 #line23 elif temp <= -10: #line24 overall_cold += 1 #line25 if all_zero: #line26 print("No Data") #line27 else: #line28 print(f"Day Average: {day_total/day_valid:.2f}") #line30 overall_total += day_total #line31 overall_valid += day_valid #line32 day += 1 #line33 if overall_valid > 0: #line34 print(f"Overall: Hot Cold = {overall_hot} {overall_cold}\nOverall Average: {overall_total/overall_valid:.2f}") #line35 else: #line37 print("No valid temperature readings") #line38 print(26) ``` ![image](https://hackmd.io/_uploads/HyIbnOqo1g.png) ```python= cars, trips = int(input()), int(input()) d1 = float(input()) # line3: Car 1, Trip 1 distance f1 = float(input()) # line4: Car 1, Trip 1 fuel d2 = float(input()) # line5: Car 1, Trip 2 distance f2 = float(input()) # line6: Car 1, Trip 2 fuel d3 = float(input()) # line7: Car 2, Trip 1 distance f3 = float(input()) # line8: Car 2, Trip 1 fuel d4 = float(input()) # line9: Car 2, Trip 2 distance f4 = float(input()) # line10: Car 2, Trip 2 fuel overall_total = total_trips = 0 for i in range(cars): # line13 car_total = 0 for j in range(trips): # line14 if i == 0: if j == 0: eff = d1 / f1 elif j == 1: eff = d2 / f2 else: if j == 0: eff = d3 / f3 elif j == 1: eff = d4 / f4 car_total += eff # line16 overall_total += eff # line17 total_trips += 1 # line18 print(round(car_total/trips, 1)) # line20 print(f'Overall Average: {overall_total / total_trips:.1f}\n15') ``` ![image](https://hackmd.io/_uploads/SkYa3uqikx.png) ```python False ``` ![image](https://hackmd.io/_uploads/BJSxpd5s1g.png) ```python True ``` ![image](https://hackmd.io/_uploads/rJ9zaO5skg.png) ```python False ``` ![image](https://hackmd.io/_uploads/B19Va_qokg.png) ```python False ``` ![image](https://hackmd.io/_uploads/rJSIpd5jkg.png) ```python False ``` ![image](https://hackmd.io/_uploads/HJXup_9oJe.png) ```python False ``` ![image](https://hackmd.io/_uploads/H1vYaO5j1g.png) ```python True ``` ![image](https://hackmd.io/_uploads/Skto6O5sJl.png) ```python True ``` ![image](https://hackmd.io/_uploads/SylapO9syg.png) ```python False ``` ![image](https://hackmd.io/_uploads/SkPR6d9iJx.png) ```python n = int(input()) for i in range(1, 11): print(n * i) ``` ![image](https://hackmd.io/_uploads/HyHvCdciyg.png) ```python= buses, trips = int(input()), int(input()) d1, d2, d3, d4 = int(input()), int(input()), int(input()), int(input()) total_distance = 0 for i in range(buses): # line8 bus_distance = 0 # line9 j = 0 # line10 while j < trips: # line11 if i == 0: # line12 if j == 0: # line13 distance = d1 # line14 elif j == 1: # line15 distance = d2 # line16 else: # line17 if j == 0: # line18 distance = d3 # line19 elif j == 1: # line20 distance = d4 # line21 bus_distance += distance # line22 total_distance += distance # line23 j += 1 print(bus_distance) # line24 print(f'Total Distance: {total_distance}\n11') ``` ![image](https://hackmd.io/_uploads/ByRFkKciyg.png) ```python= t = 0 for i in range(1, int(input())+1): w, e, g = i * 10, i * 15, i * 5 if i % 2 == 0: e *= 0.9 if i % 3 == 0: g *= 1.05 t += w + e + g print(round(t)) ``` ![image](https://hackmd.io/_uploads/HkpTJtqjJe.png) ```python= print(int(input()) * 5) ``` ![image](https://hackmd.io/_uploads/rJ37gK9o1g.png) ```python= t = 0 for _ in range(int(input())): t += int(input()) print(t) ``` ![image](https://hackmd.io/_uploads/HJWBbYqokx.png) ```python= t = 0 for i in range(1, int(input())+1): for j in range(1, 4): t += i * j * 2 print(t) ``` ![image](https://hackmd.io/_uploads/Hkhn1QjiJg.png) ```python= t = 0 for i in range(1, int(input())+1): t += i print(t) ``` ![image](https://hackmd.io/_uploads/SyUzeXjsJx.png) ```python= for i in range(1, int(input())+1): print(i ** 2) ``` ![image](https://hackmd.io/_uploads/B1aSlQooJl.png) ```python= print(int(input()) / 2) ``` ![image](https://hackmd.io/_uploads/Bkktlmsjkl.png) ```python= stores, days = int(input()), int(input()) sale1, sale2, sale3, sale4 = int(input()), int(input()), int(input()), int(input()) overall_total = 0 # line7 for i in range(stores): store_total = 0 for j in range(days): # line9 if i == 0: if j == 0: sale = sale1 elif j == 1: sale = sale2 else: if j == 0: sale = sale3 elif j == 1: sale = sale4 store_total += sale # line11 print(store_total / days) overall_total += store_total # line14 print(f'Overall Average: {overall_total/(stores*days)}\n10') ``` ![image](https://hackmd.io/_uploads/rJPfW7joke.png) ```python= students, days = int(input()), int(input()) s1_day1, s1_day2, s1_day3, s2_day1, s2_day2, s2_day3 = int(input()), int(input()), int(input()), int(input()), int(input()), int(input()) total_pages = 0 # line9 for i in range(students): # line10 student_total = j = 0 while j < days: # line13 if i == 0: if j == 0: pages = s1_day1 # line14 elif j == 1: pages = s1_day2 # line15 elif j == 2: pages = s1_day3 # line16 else: if j == 0: pages = s2_day1 # line17 elif j == 1: pages = s2_day2 # line18 elif j == 2: pages = s2_day3 # line19 student_total += pages # line20 total_pages += pages # line21 j += 1 # line22 print(student_total) # line23 print(f'Total Pages: {total_pages}\n22') ``` ![image](https://hackmd.io/_uploads/Hk7xG7sjkg.png) ```python= stalls, products = int(input()), int(input()) price1, qty1, price2, qty2, price3, qty3, price4, qty4 = int(input()), int(input()), int(input()), int(input()), int(input()), int(input()), int(input()), int(input()) total_revenue = 0 # line11 for i in range(stalls): # line12 stall_revenue = 0 # line13 for j in range(products): # line14 if i == 0: if j == 0: revenue = price1 * qty1 elif j == 1: revenue = price2 * qty2 else: if j == 0: revenue = price3 * qty3 elif j == 1: revenue = price4 * qty4 # line15 stall_revenue += revenue # line16 print(stall_revenue) # line17 total_revenue += stall_revenue # line18 print(f'Total Revenue: {total_revenue}\n15') ``` ![image](https://hackmd.io/_uploads/H1G9MXiokl.png) ```python= baskets, compartments = int(input()), int(input()) b1_c1, b1_c2, b1_c3, b2_c1, b2_c2, b2_c3 = int(input()), int(input()), int(input()), int(input()), int(input()), int(input()) total_weight = i = 0 # line10 while i < baskets: # line11 basket_total = 0 # line12 for j in range(compartments): # line13 if i == 0: if j == 0: weight = b1_c1 # line14 elif j == 1: weight = b1_c2 # line15 elif j == 2: weight = b1_c3 # line16 else: if j == 0: weight = b2_c1 # line17 elif j == 1: weight = b2_c2 # line18 elif j == 2: weight = b2_c3 # line19 basket_total += weight # line20 total_weight += weight # line21 print(basket_total) # line23 i += 1 # line24 print(f'Total Weight: {total_weight}\n22') ``` ![image](https://hackmd.io/_uploads/S1q7Qmoj1l.png) ```python= print(int(input()) ** 2) ``` ![image](https://hackmd.io/_uploads/S1ewQ7so1l.png) ```python= t = 0 for i in range(1, int(input())+1): for j in range(1, 8): ds = (i+j)%10 + 5 if ds % 2: ds += 3 t += ds print(t) ``` ![image](https://hackmd.io/_uploads/BJDW4QiiJx.png) ```python= n = 0 for _ in range(int(input())): if int(input()) >= 60: n += 1 print(n) ``` ![image](https://hackmd.io/_uploads/H1j847iikl.png) ```python= rows, cols, severe_count, unhealthy_count = int(input()), int(input()), 0, 0 for r in range(rows): # line5 for c in range(cols): # line6 pollution = int(input()) # line7 if pollution < 0 or pollution > 300: # line8 print("Invalid") # line9 continue # line10 if pollution == 150: # line11 print("Skip") # line12 continue # line13 if pollution > 200: # line14 print("Severe") # line15 severe_count += 1 # line16 elif 100 <= pollution <= 200: # line17 print("Unhealthy") # line18 unhealthy_count += 1 # line19 else: # line20 print("Good") # line21 print() # line22 print(f'Severe: {severe_count} , Unhealthy: {unhealthy_count}\n13') ``` ![image](https://hackmd.io/_uploads/H1FlB7jskg.png) ```python= t, s = 0, int(input()) for _ in range(8): t += s s += 5 print(t) ``` ![image](https://hackmd.io/_uploads/S1tqSmsoyg.png) ```python= t = 0 for i in range(1, int(input())+1): for j in range(1, 4): v = (i+j) * 5 if j == 2: v -= 3 t += max(v, 0) print(t) ``` ![image](https://hackmd.io/_uploads/BkKSIXssyl.png) ```python= n = 0 for i in range(1, int(input())+1): for j in range(1, 6): t = (i*j)%5 + 3 n += t if t!=3 else t*2 print(n) ``` ![image](https://hackmd.io/_uploads/SJeJPQjjye.png) ```python= for _ in range(int(input())): print(round(int(input())*9/5 + 32)) ``` ## 作業三(只有一題)(3/30 11:59pm截止) ### 第一題 ```python= arr = [int(input())*12+int(input()) for _ in range(3)] print(*divmod(max(arr), 12), arr.index(max(arr))+1, sep=',') ``` ## Module 7 List 清單 ![image](https://hackmd.io/_uploads/SJ4SPXoiyx.png) ```python False ``` ![image](https://hackmd.io/_uploads/BkNRV312yl.png) ```python True ``` ![image](https://hackmd.io/_uploads/Skj9Bnk3Je.png) ```python= print(min(map(int, input().split()))) ``` ![image](https://hackmd.io/_uploads/rkqPH2khJg.png) ```python= a = list(map(int, input().split())) a.append(sum(a)) print(a[::-1]) ``` ![image](https://hackmd.io/_uploads/BkreU2J31g.png) ```python= a = list(map(int, input().split())) if len(a) > 1: a.remove(min(a)) a.sort() print(f'{a}\n{sum(a)/len(a):.1f}') ``` ![image](https://hackmd.io/_uploads/S1oVv2121e.png) ```python= d = {} for i in input().split(';'): if i in d.keys(): d[i] += 1 else: d[i] = 1 print(list(d.keys()), list(d.values()), sep='\n') ``` ![image](https://hackmd.io/_uploads/SJZcFhJnJg.png) ```python= a = list(map(int, input().split())) b = [i for i in a if i > sum(a)/len(a)] b.sort() print(b) ``` ![image](https://hackmd.io/_uploads/S1cMoh121g.png) ```python= arr, t = [], 0 for i in map(int, input().split()): t += i arr.append(t) print(arr) ``` ![image](https://hackmd.io/_uploads/HygLwGbn1g.png) ```python= print(list(map(lambda x: x*2 if x%2==0 else x, map(int, input().split())))) ``` ![image](https://hackmd.io/_uploads/H1u7uMW3Je.png) ```python= a = list(map(int, input().split())) print(list(map(lambda x: x+5, a)), a, 5, sep='\n') ``` ![image](https://hackmd.io/_uploads/HyqiYM-nJl.png) ```python= ids = input().split() ids = [int(x) for x in ids if int(x) % 2] print(ids[::-1], 5, sep='\n') ``` ![image](https://hackmd.io/_uploads/S12JcGZ3yg.png) ```python= sales = list(set(map(int, input().split()))) sales.sort() print(sales, 7, sep='\n') ``` ![image](https://hackmd.io/_uploads/BJhzoGbhye.png) ```python= a = list(map(int, input().split())) a.remove(min(a)) a.remove(max(a)) print(a, 7, sep='\n') ``` ![image](https://hackmd.io/_uploads/r1OpsMZnye.png) ```python= a = list(map(int, input().split())) print(list(map(lambda x: x+1, a)), a, 5, sep='\n') ``` ![image](https://hackmd.io/_uploads/SyWFk7-21l.png) ```python= import re print(list(map(int, re.split(r'[ ,]', input())))) ``` ![image](https://hackmd.io/_uploads/rJ46eXW21g.png) ```python= a = tuple(map(float, input().split())) print(round(sum(a)/len(a), 2)) ``` ![image](https://hackmd.io/_uploads/rkaPWm-3yg.png) ```python= a = list(map(float, input().split())) print([sum(a)] + a + [round(sum(a)/len(a), 1)]) ``` ![image](https://hackmd.io/_uploads/By5mGQZnJg.png) ```python= print(list(map(lambda x: x*2, map(int, input().split())))) ``` ![image](https://hackmd.io/_uploads/SJtTfQb21x.png) ```python= print(list(map(int, input().split()))[::-1]) ``` ![image](https://hackmd.io/_uploads/S1x-QX-n1l.png) ```python= print(list(map(lambda x:x+1, map(int, input().split())))) ``` ![image](https://hackmd.io/_uploads/Byuv7QZ2kl.png) ```python True ``` ![image](https://hackmd.io/_uploads/ByPomXW3yl.png) ```python False ``` ![image](https://hackmd.io/_uploads/HJ0mNm-2kx.png) ```python= a = list(map(int, input().split())) + list(map(int, input().split())) a.sort() print(a, 4, sep='\n') ``` ![image](https://hackmd.io/_uploads/ryAZBmWhkg.png) ```python= print([i for i in map(int, input().split()) if i%2==0]) ``` ![image](https://hackmd.io/_uploads/Bku7HQ-3Jx.png) ```python True ``` ![image](https://hackmd.io/_uploads/BkmvBQ-nke.png) ```python= print(sum(i for i in map(int, input().split()) if i>=50), 6, sep='\n') ``` ![image](https://hackmd.io/_uploads/ryA48mb3yl.png) ```python True ``` ![image](https://hackmd.io/_uploads/HJTFIXbhyg.png) ```python False ``` ![image](https://hackmd.io/_uploads/Hy_2L7-2yl.png) ```python False ``` ![image](https://hackmd.io/_uploads/SJbRIm-2kl.png) ```python= a = list(map(int, input().split())) print([] if len(a)<3 else a[1:-1]) ``` ![image](https://hackmd.io/_uploads/HklHwmW2yg.png) ```python= a = list(map(int, input().split())) print([a[-1]]+a[1:-1]+[a[0]] if len(a)>1 else a, 5, sep='\n') ``` ![image](https://hackmd.io/_uploads/r1uZdXb31e.png) ```python= print(round(sum(map(float, input().split())), 1)) ``` ![image](https://hackmd.io/_uploads/SkFhdmbhyx.png) ```python= a = input().split(';') a.sort() print(a) ``` ![image](https://hackmd.io/_uploads/SJvktmb31e.png) ```python= print(list(map(int, input().split()))[1:-1][::-1], 3, sep='\n') ``` ![image](https://hackmd.io/_uploads/ByTLKmWnJl.png) ```python False ``` ![image](https://hackmd.io/_uploads/BJEFFXZ2kx.png) ```python= print([input().title() for _ in range(int(input()))]) ``` ![image](https://hackmd.io/_uploads/HkmAFX-nJl.png) ```python= a = list(map(int, input().split(','))) a.sort() print(a) ``` ![image](https://hackmd.io/_uploads/B1rQ9Qbn1x.png) ```python False ``` ![image](https://hackmd.io/_uploads/HJpVc7Z2yl.png) ```python= print(max(map(float, input().split(',')))) ``` ![image](https://hackmd.io/_uploads/HkCu9mWh1e.png) ```python False ``` ## 作業四 (只有一題除錯題) (4/13 11:59pm 截止) ```python= m, n, q = map(int, input().strip().split(',')) matrix = [list(map(int, input().strip().split(','))) for i in range(m)] journeys = [[] for _ in range(q+1)] for j in range(n): for i in range(m): pid = matrix[i][j] if pid != 0: journeys[pid].append(i) one_change = two_change = 0 for pid in range(1, q + 1): if len(journeys[pid]) == 0: continue changes = 0 for i in range(1, len(journeys[pid])): if journeys[pid][i] != journeys[pid][i - 1]: changes += 1 if changes == 1: one_change += 1 elif changes == 2: two_change += 1 print(f'{one_change},{two_change}') ``` ## Module 8 作業管理與演算法應用 ![image](https://hackmd.io/_uploads/r16Xwab3yl.png) ```python True ``` ![image](https://hackmd.io/_uploads/HJbLvTbhJe.png) ```python= r = int(input()) arr = list(map(int, input().split())) if r == 15: stock = 250 q = 150 elif r == 20: stock = 500 q = 200 else: stock = 300 q = 150 t = 0 for i in arr: stock -= i if stock < r: stock += q t += 1 print(t) ``` ![image](https://hackmd.io/_uploads/S1pnd6Wnyg.png) ```python= d = int(input()) arr = list(map(int, input().split())) ttl, t = 0, 0 for i in arr: ttl += i if ttl > d: break t += 1 print(t) ``` ![image](https://hackmd.io/_uploads/rks5f5znJg.png) ```python= t = int(input()) arr = list(map(int, input().split())) n = len(arr) left, current_sum, min_length = 0, 0, n + 1 for right in range(n): current_sum += arr[right] while current_sum >= t: min_length = min(min_length, right - left + 1) current_sum -= arr[left] left += 1 print(min_length if min_length<=n else 0) ``` ![image](https://hackmd.io/_uploads/rJ-RfqMh1x.png) ```python= a = list(map(int, input().split())) a.sort() m = a[len(a)//2 if len(a)%2 else len(a)//2-1] print(m, len([i for i in a if i > m])) ``` ![image](https://hackmd.io/_uploads/Bk3DE5f2ke.png) ```python= pos = neg = 0 arr = list(map(int, input().split())) for i in range(1, len(arr)): d = arr[i] - arr[i-1] if d > 0: pos = max(pos, d) elif d < 0: neg = min(neg, d) print(pos, neg) ``` ![image](https://hackmd.io/_uploads/ByHkvqf3Je.png) ```python= num_jobs, num_machines, processing_times = int(input()), int(input()), input().split() jobs = [] # line 4 for time in processing_times: # line 5 t = int(time) # line 6 if t > 0 and t <= 500: # line 7 jobs.append(t) # line 8 jobs.sort(reverse=True) # line 9 loads = [0] * num_machines # line 10 # Assign jobs using LPT rule for job in jobs: # line 11 # Find machine with minimum load least_loaded_machine = 0 # line 12 least_loaded = loads[0] # line 13 for i in range(1, num_machines): # line 14 if loads[i] < least_loaded: # line 15 least_loaded_machine = i # line 16 least_loaded = loads[i] # line 17 loads[least_loaded_machine] += job # line 18 print(f'Machine loads: {loads}\nMakespan: {max(loads)}\n15') ``` ![image](https://hackmd.io/_uploads/rkzOk472ke.png) ```python= init_inventory, reorder_point, order_qty, num_days = int(input()), int(input()), int(input()), int(input()) daily_sales = list(map(int, input().split())) inventory, total_cost, ordering_cost, holding_cost = init_inventory, 0, 100, 3 for day in range(1, num_days + 1): # line 10 sales = daily_sales[day - 1] # line 11 if sales < 0 or sales > 100: # line 12 total_cost += inventory * holding_cost print(f"Day {day}: Inventory = {inventory}, No order placed") continue # line 13 inventory -= sales inventory = max(0, inventory) total_cost += inventory * holding_cost if inventory < reorder_point: # line 18 inventory += order_qty total_cost += ordering_cost print(f"Day {day}: Inventory = {inventory}, Order placed") # line 21 else: print(f"Day {day}: Inventory = {inventory}, No order placed") # line 22 print(f"Total cost: {total_cost}\n13") ``` ![image](https://hackmd.io/_uploads/ryBlXNmh1l.png) ```python= n, distances, route, total_distance = int(input()), [], [0], 0 visited = [False] * n for i in range(n): # line 6 row = list(map(int, input().split())) # line 7 distances.append(row) # line 8 current, visited[0] = 0, True for _ in range(n - 1): # line 11 min_dist = float('inf') # line 12 next_loc = -1 # line 13 for j in range(n): # line 14 if not visited[j]: if distances[current][j] <= min_dist: # line 15 min_dist = distances[current][j] # line 16 next_loc = j # line 17 visited[next_loc] = True # line 18 route.append(next_loc) # line 19 total_distance += min_dist # line 20 current = next_loc # line 21 route.append(0) # line 22 total_distance += distances[current][0] # line 23 print(f'Route: {route}\nTotal distance: {total_distance}\n15') ``` ![image](https://hackmd.io/_uploads/r1j674731x.png) ```python= num_jobs, jobs, position_changes = int(input()), [], 0 jobs_input = list(map(int, input().split())) for i in range(num_jobs): # line 5 time = jobs_input[i] # line 6 if time < 1 or time > 480: # line 7 print(f"Job {i+1} skipped: Invalid processing time") # line 8 continue # line 9 if len(jobs) == 0: # line 10 jobs.append(time) # line 11 print(f"After job {i+1}: {jobs}") # line 12 continue # line 13 jobs.append(time) # line 14 current_pos = len(jobs) - 1 # line 15 while current_pos > 0 and jobs[current_pos-1] > jobs[current_pos]: # line 16 jobs[current_pos], jobs[current_pos-1] = jobs[current_pos-1], jobs[current_pos] # line 17 position_changes += 1 # line 18 current_pos -= 1 # line 19 print(f"After job {i+1}: {jobs}") # line 20 print(f"Position changes needed: {position_changes}\n15") ``` ![image](https://hackmd.io/_uploads/Sk3r4N72Jg.png) ```python= num_slots, treatment_times, patient_numbers, waiting_times, total_wait = int(input()), [], [], [], 0 treatment_str, treatment_tokens = input(), [] for token in treatment_str.split(): # line 7 treatment_tokens.append(int(token)) # line 8 for i in range(num_slots): # line 9 time = treatment_tokens[i] # line 10 if 10 <= time <= 120: # line 11 treatment_times.append(time) # line 12 patient_numbers.append(i + 1) # line 13 # Sort treatment_times in ascending order along with corresponding patient_numbers for i in range(len(treatment_times)): # line 14 for j in range(len(treatment_times) - 1): # line 15 if treatment_times[j] > treatment_times[j + 1]: # line 16 treatment_times[j], treatment_times[j + 1] = treatment_times[j + 1], treatment_times[j] # line 17 patient_numbers[j], patient_numbers[j + 1] = patient_numbers[j + 1], patient_numbers[j] # line 18 current_wait = 0 # line 19 for i in range(len(treatment_times)): # line 20 waiting_times.append(current_wait) # line 21 total_wait += current_wait current_wait += treatment_times[i] # line 23 if len(waiting_times) > 0: # line 23 avg_wait = total_wait / len(waiting_times) # line 24 else: avg_wait = 0 # line 25 print(f'Patient order: {patient_numbers}\nTreatment times: {treatment_times}\nWaiting times: {waiting_times}\nAverage waiting time: {avg_wait:.2f} minutes\n24') ``` ![image](https://hackmd.io/_uploads/SyuXBV7hkg.png) ```python= num_loc, dst = int(input()), [] matrix_str = input() # line 3 rows = matrix_str.split(';') # line 4 for row in rows: # line 5 row_values = [int(x) for x in row.split()] # line 6 # Remove any negative distances row_values = [x for x in row_values if x >= 0] # line 7 dst.append(row_values) # line 8 origin, total_distance = 0, 0 tour = [origin] unvisited = list(range(num_loc)) # line 12 unvisited.remove(origin) # line 13 cur = origin # line 14 for _ in range(num_loc - 1): # line 15 next_loc = None # line 16 min_dst = float('inf') # line 17 for j in unvisited: # line 18 if dst[cur][j] < min_dst: # line 19 min_dst = dst[cur][j] # line 20 next_loc = j # line 21 if next_loc is None: # line 22 next_loc = unvisited[0] min_dst = dst[cur][next_loc] tour.append(next_loc) # line 23 total_distance += min_dst # line 24 unvisited.remove(next_loc) # line 25 cur = next_loc # line 26 total_distance += dst[cur][origin] # line 27 tour.append(origin) # line 28 print(f'Tour: {tour}\nTotal distance: {total_distance}\n17') ``` ![image](https://hackmd.io/_uploads/SyT58V7hye.png) ```python= n = int(input()) sales = list(map(int, input().split())) res = list(map(int, input().split())) for i in range(len(sales)): n = n - sales[i] + res[i] n = max(n, 0) print(n, end=' ') ``` ![image](https://hackmd.io/_uploads/ryx0or72Jx.png) ```python= n = int(input()) arr = list(map(int, input().split())) work = [0] * n for i in arr: for j in range(len(work)): if work[j] == min(work): work[j] += i break print(max(work) - min(work)) ``` ![image](https://hackmd.io/_uploads/SksNpHQhJx.png) ```python= m = n = 0 for i in range(1, int(input())+1): s = sum(map(int, input().split())) if s > n: n = s m = i print(m, n) ``` ![image](https://hackmd.io/_uploads/B1A10HQhkl.png) ```python= k = int(input()) arr = list(map(int, input().split())) for i in range(len(arr)-k+1): print(sum(arr[i:k+i])//k, end=' ') ``` ![image](https://hackmd.io/_uploads/rJerkIXhyl.png) ```python= init = int(input()) sales = list(map(int, input().split())) mi, md = init, 1 for i in range(1, len(sales)+1): init -= sales[i-1] init = max(0, init) if init < mi: mi = init md = i print(md, mi) ``` ![image](https://hackmd.io/_uploads/S1msZUmnyl.png) ```python= init, book, arr = int(input()), int(input()), list(map(int, input().split())) for i in range(1, len(arr)+1): init -= arr[i-1] if init <= 0: init = book print(init) ``` ![image](https://hackmd.io/_uploads/SJkwDU7nyl.png) ```python True ``` ![image](https://hackmd.io/_uploads/S13dPUQ31x.png) ```python False ``` ![image](https://hackmd.io/_uploads/H1YqvU72yx.png) ```python= print(int(input()) - sum(map(int, input().split()))) ``` ![image](https://hackmd.io/_uploads/r1VOuLm2ke.png) ```python= init, r, q = int(input()), int(input()), int(input()) for i in map(int, input().split()): init -= i if init < r: init += q print(init) ``` ![image](https://hackmd.io/_uploads/H1CEYU72yl.png) ```python= print(sum(map(int, input().split()))) ``` ![image](https://hackmd.io/_uploads/SkTDFIm2Jl.png) ```python False ``` ![image](https://hackmd.io/_uploads/r1ftKLQhJe.png) ```python= init = int(input()) t = 0 for i in map(int, input().split()): init -= i if init < 0: init += 300 t += 1 print(t) ``` ![image](https://hackmd.io/_uploads/rybr5LQ3yl.png) ```python= n = int(input()) print(n > 0 and (n & (n-1)) == 0) ``` ![image](https://hackmd.io/_uploads/rybuhIQ21x.png) ```python= cost, q, s = int(input()), int(input()), sum(map(int, input().split())) print(cost*s//2 if s>q else cost*s) ``` ![image](https://hackmd.io/_uploads/rkXqhIXnyg.png) ```python True ``` ![image](https://hackmd.io/_uploads/Bypj3L72ye.png) ```python True ``` ![image](https://hackmd.io/_uploads/BJt0nI72Jl.png) ```python= a, b, c = int(input()), int(input()), int(input()) print(a+c if a<=b else a) ``` ![image](https://hackmd.io/_uploads/Bk1uaLmhkx.png) ```python True ``` ![image](https://hackmd.io/_uploads/rkhKpIXhyx.png) ```python True ``` ![image](https://hackmd.io/_uploads/r1b3a8Qnyx.png) ```python False ``` ![image](https://hackmd.io/_uploads/SkQ06Im3ye.png) ```python True ``` ![image](https://hackmd.io/_uploads/HkglRL73yl.png) ```python False ``` ![image](https://hackmd.io/_uploads/ryT-AIQ2ye.png) ```python True ``` ![image](https://hackmd.io/_uploads/H1w7A8mnyg.png) ```python True ``` ![image](https://hackmd.io/_uploads/S1WSCLmn1x.png) ```python= arr = list(map(int, input().split())) mac = int(input()) arr.sort(reverse=True) now = [0] * mac for i in arr: for j in range(len(now)): if now[j] == min(now): now[j] += i break print(max(now)) ``` ![image](https://hackmd.io/_uploads/Sk-6yPQh1x.png) ```python= need, w, arr = int(input()), int(input()), tuple(map(int, input().split())) print(max(0, need+arr[-1]-w)) ``` ![image](https://hackmd.io/_uploads/HyGDWDXhJl.png) ```python True ``` ## 作業五 (只有一題) (4/27 11:59pm 截止) ```python= m, n, q = map(int, input().strip().split(',')) arr = [list(map(int, input().strip().split(','))) for i in range(m)] once = twice = 0 p = [[] for _ in range(q+1)] for j in range(n): for i in range(m): pid = arr[i][j] if pid != 0: p[pid].append(i) for pid in range(1, q + 1): if len(p[pid]) == 0: continue ch = 0 for i in range(1, len(p[pid])): if p[pid][i] != p[pid][i-1]: ch += 1 if ch == 1: once += 1 elif ch == 2: twice += 1 print(once, twice, sep=',') ``` ## Module 9 函數 Function (上) ![image](https://hackmd.io/_uploads/HyG4kgYn1l.png) ```python True ``` ![image](https://hackmd.io/_uploads/BkvI1xKnkx.png) ```python= calculate_total_inventory_value = lambda p, q: sum(p*i for i in q) ``` ![image](https://hackmd.io/_uploads/BJmU-xtnyl.png) ```python= calculate_discount_price = lambda p, d: round(p * (1-d/100), 2) ``` ![image](https://hackmd.io/_uploads/BkK04emTyx.png) ```python= def days_to_finish_book(ttl, start, step): t = now = 0 while now < ttl: t += 1 now += start start += step return t ``` ![image](https://hackmd.io/_uploads/HkYy2gX6Je.png) ```python False ``` ![image](https://hackmd.io/_uploads/rJ5m3xQpJx.png) ```python= def can_fulfill_orders(arr1, arr2): if len(arr1) != len(arr2): return False for i in range(len(arr1)): if arr1[i] < arr2[i]: return False return True ``` ![image](https://hackmd.io/_uploads/Bk-Hpe7p1g.png) ```python= max_ad_profit = lambda arr, n1, n2: sum(arr[:min(n1, n2)]) ``` ![image](https://hackmd.io/_uploads/S1ds1BUT1x.png) ```python= def is_perfect_number(n): if n <= 1: return False a = 0 for i in range(1, n): if n % i == 0: a += i return a == n ``` ![image](https://hackmd.io/_uploads/HJ85gSITkl.png) ```python= def weeks_to_save(pw, goal): t = now = 0 while now < goal: t += 1 now += pw if now % 100 == 0: now += 10 return t ``` ![image](https://hackmd.io/_uploads/HyzhFePp1x.png) ```python= calculate_depreciation = lambda val, rt, y: val * ((1-rt/100)**y) ``` ![image](https://hackmd.io/_uploads/H1K6ogPpye.png) ```python= can_graduate = lambda a, b, c: (a>=70 and b<5 and c<3) or (a>90) ``` ![image](https://hackmd.io/_uploads/H1IynewTyg.png) ```python= calculate_salary = lambda b, hr, y=0: round(b + max(0, hr-160)*(b/160)*1.5 + b*0.05*y) ``` ![image](https://hackmd.io/_uploads/HkV8TgvTye.png) ```python= calculate_total_payroll = lambda arr: sum(i[0]*i[-1] for i in arr) ``` ![image](https://hackmd.io/_uploads/HJ-b0gvTyl.png) ```python= calculate_discounted_price = lambda p, d: sum(p) * (1-d) ``` ![image](https://hackmd.io/_uploads/SyxjAxPpyg.png) ```python= calculate_total_price = lambda n, p=10: n * p ``` ![image](https://hackmd.io/_uploads/ryi2Cxv6Je.png) ```python= calculate_optimal_revenue = lambda arr: sum(i[0]*(1-i[-1]/100) for i in arr) ``` ![image](https://hackmd.io/_uploads/ryzayZPT1g.png) ```python False ``` ![image](https://hackmd.io/_uploads/HkaAJbwp1l.png) ```python= calculate_tax = lambda t: t*0.03 if t<10000 else t*0.05 if t>20000 else t*0.04 ``` ![image](https://hackmd.io/_uploads/SJ1LlZvakl.png) ```python False ``` ![image](https://hackmd.io/_uploads/HJIvlZDTJl.png) ```python False ``` ![image](https://hackmd.io/_uploads/BkauxWwake.png) ```python= promo_calculator = lambda p, q, d: p * q * (1-d/100) ``` ![image](https://hackmd.io/_uploads/rkjeW-wa1l.png) ```python= calculate_order_cost = lambda p, r: p * (1+r/100) ``` ![image](https://hackmd.io/_uploads/SkhvZZwa1g.png) ```python True ``` ![image](https://hackmd.io/_uploads/Sk0F--wpJg.png) ```python= calculate_break_even_point = lambda c, u, p: float('inf') if u>=p else int(c/(p-u)) + (1 if c/(p-u)%1 else 0) ``` ![image](https://hackmd.io/_uploads/SkfcGZw6ke.png) ```python False ``` ![image](https://hackmd.io/_uploads/B1chMWw6kl.png) ```python False ``` ![image](https://hackmd.io/_uploads/SJi0fZPaye.png) ```python True ``` ![image](https://hackmd.io/_uploads/B1ylQZPTJx.png) ```python= calculate_total_cost = lambda p, q: p * q * (1 if q<=10 else 0.9) ``` ![image](https://hackmd.io/_uploads/BJuPXZPTkl.png) ```python= calculate_discount = lambda p: 0.0 if p<100 else 5.0 if p<=500 else 10.0 ``` ![image](https://hackmd.io/_uploads/BJkq4ZPTkg.png) ```python True ``` ## 作業六 (只有一題) (5/11 11:59pm 截止) ```python= def f(s): s = ''.join(sorted(str(s).zfill(4))) r = s[::-1] return abs(int(s)-int(r)) n = int(input()) ans = [] if n!=6174 else [6174] while n != 6174: n = f(n) ans.append(n) print(*ans, sep=',') ``` ## Module 10 函數 Function (下) ![image](https://hackmd.io/_uploads/ryUTEWva1x.png) ```python False ``` ![image](https://hackmd.io/_uploads/rkKCE-w61g.png) ```python= calculate_total_with_discount = lambda n, d: round(1.2 * n * (1-d/100), 2) ``` ![image](https://hackmd.io/_uploads/r1zOrWvaJx.png) ```python= calculate_total = lambda arr1, arr2: sum(arr1[i]*arr2[i] for i in range(len(arr1))) if len(arr1)==len(arr2) else -1 ``` ![image](https://hackmd.io/_uploads/ByuhUbD61g.png) ```python= apply_discount = lambda arr, d: [i*(1-d/100) for i in arr] ``` ![image](https://hackmd.io/_uploads/BJVA8bvayl.png) ```python= allocate_inventory = lambda a1, a2: [max(0, a1[i]-a2[i]) for i in range(len(a1))] ``` ![image](https://hackmd.io/_uploads/Sk9LvbPT1x.png) ```python= calculate_total_revenue = lambda a: sum(i[-1] for i in a) ``` ![image](https://hackmd.io/_uploads/r1v2wZwpyg.png) ```python= def determine_optimal_price(a, b): m = p = o = 0 for p in range(a//b + 1): i = (a-b*p) * p if i > m: m, o = i, p return o ``` ![image](https://hackmd.io/_uploads/ry4yY-DpJx.png) ```python= compute_discounted_price = lambda op, dp: round(op - (op*dp/100), 2) ``` ![image](https://hackmd.io/_uploads/BJNVtZPa1g.png) ```python= calculate_bulk_discount = lambda q, d: round(q * 2.5 * (0.9 if q>=d else 1), 2) ``` ![image](https://hackmd.io/_uploads/HyzecZD61g.png) ```python= calculate_cost_with_tax = lambda p, r: round(p * (1+r/100), 2) ``` ![image](https://hackmd.io/_uploads/H1qS5ZPTye.png) ```python= find_sales_bounds = lambda arr: (round(min(arr), 2), round(max(arr), 2)) ``` ![image](https://hackmd.io/_uploads/HksCcZDpJe.png) ```python= calculate_multiple_purchases = lambda q, p: round(sum(i * p for i in q), 2) ``` ![image](https://hackmd.io/_uploads/Sk1TiWPT1l.png) ```python= def calculate_stocking_cost(q, p): if type(q) is int and type(p) is float: if p >= 0 and q >= 0: return p * q ``` ![image](https://hackmd.io/_uploads/SkATnWw6ye.png) ```python= calculate_total_costs = lambda a1, a2: [] if len(a1)!=len(a2) else [a1[i]*a2[i] for i in range(len(a1))] ``` ![image](https://hackmd.io/_uploads/BJcna-vT1l.png) ```python True ``` ![image](https://hackmd.io/_uploads/r1706bwayg.png) ```python False ``` ![image](https://hackmd.io/_uploads/H1dyAbv6kx.png) ```python False ``` ![image](https://hackmd.io/_uploads/ByOWAbD6Jx.png) ```python True ``` ![image](https://hackmd.io/_uploads/BJnfCZvT1x.png) ```python False ``` ![image](https://hackmd.io/_uploads/rkyECZvTJl.png) ```python= calculate_average_price = lambda arr: round(sum(arr) / len(arr), 2) ``` ![image](https://hackmd.io/_uploads/SJhPCWP6Jg.png) ```python True ``` ![image](https://hackmd.io/_uploads/rk650ZP6Jg.png) ```python True ``` ![image](https://hackmd.io/_uploads/HkGnR-Ppke.png) ```python True ``` ![image](https://hackmd.io/_uploads/B1NaAWPp1g.png) ```python= calculate_total_amount = lambda n: n * 1.2 ``` ![image](https://hackmd.io/_uploads/S1J-Jzvpyg.png) ```python= def calculate_total_cost(items): t = 0 if not items: return total_cost for i in items: if not isinstance(i, tuple) or len(i) != 2: return 0 if not isinstance(i[0], int) or not isinstance(i[1], (int, float)): return 0 if i[0] < 0 or i[1] < 0: return 0 t += i[0] * i[1] return round(t, 2) ``` ![image](https://hackmd.io/_uploads/ByybeMvaye.png) ```python True ``` ![image](https://hackmd.io/_uploads/H14fxzDpkx.png) ```python True ``` ![image](https://hackmd.io/_uploads/S1wXxfvaye.png) ```python True ``` ![image](https://hackmd.io/_uploads/rkpNlMDTyg.png) ```python True ``` >由於有一題的題目只有英文 我將其report了 >但report的題目會看不到 因此本筆記此單元將會少一題 >若有人有該題目 可以與我聯繫 感謝! ## 作業七 (只有一題) (5/ 25 11:59pm 截止) ```python= def try_to_sell(current_sales, c_id, c_pref, s_start, s_end): success = False assigned_seat = 0 m = len(current_sales) n = len(current_sales[0]) segments = list(range(s_start-1, s_end-1)) all_seats = list(range(1, m + 1)) odd_seats = [i for i in all_seats if i % 2 == 1] even_seats = [i for i in all_seats if i % 2 == 0] if c_pref == 0: seat_check_order = all_seats elif c_pref == 1: seat_check_order = odd_seats + even_seats elif c_pref == 2: seat_check_order = even_seats + odd_seats for i in seat_check_order: if all(current_sales[i-1][j] == 0 for j in segments): success = True assigned_seat = i break return success, assigned_seat m, n, q = map(int, input().split(',')) current_sales = [[0 for _ in range(n)] for _ in range(m)] for c_id in range(1, q+1): s_start, s_end, c_pref = map(int, input().split(',')) success, seat = try_to_sell(current_sales, c_id, c_pref, s_start, s_end) if success: for t in range(s_start-1, s_end-1): current_sales[seat-1][t] = c_id for row in current_sales: print(*row, sep=',') ``` ## 測驗考古題下載 Past Exam ![image](https://hackmd.io/_uploads/HJILCPaC1x.png) ```python True ``` ## Module 11 字串String ![image](https://hackmd.io/_uploads/rkwbC54R1l.png) ```python True ``` ![image](https://hackmd.io/_uploads/H1yV0cE0Jg.png) ```python= def merge_sorted_strings(arr1, arr2): arr = arr1 + arr2 arr.sort() return arr ``` ![image](https://hackmd.io/_uploads/HyNi0qVCkg.png) ```python= num = '1234567890' def clean_and_average_prices(p): if p == ['$']: return 0 new = [] for i in p: i = i.replace('$', '').strip() if i: new.append(float(i)) return round(sum(new)/len(new), 2) ``` ![image](https://hackmd.io/_uploads/ryQe-iN0ke.png) ```python= def find_longest_common_prefix(arr): ans = arr[0] for i in arr: for j in range(min(len(ans), len(i))): if i[j] == ans[j]: continue ans = ans[:j] break return ans ``` ![image](https://hackmd.io/_uploads/B1N8NoN0Jg.png) ```python= def optimize_stock_levels(p, l): ans = [] for i in range(len(p)): if p[i] < 20: ans.append(l[i] * 2) elif p[i] > 50: ans.append(l[i] // 2) else: ans.append(l[i]) return ans ``` ![image](https://hackmd.io/_uploads/Sym7UjECkl.png) ```python= def arrange_inventory_shelves(arr1, arr2): if len(arr1) < len(arr2): for _ in range(len(arr2)-len(arr1)): arr1.append('Unknown') elif len(arr1) > len(arr2): for _ in range(len(arr1)-len(arr2)): arr2.append('Unknown') return list(zip(arr1, arr2)) ``` ![image](https://hackmd.io/_uploads/H1KetAp0ke.png) ```python= validate_string_inputs = lambda arr: [i.isalpha() for i in arr] ``` ![image](https://hackmd.io/_uploads/S1PAiCaRJg.png) ```python= convert_date_format = lambda s: f'{s[4:]}-{s[:2]}-{s[2:4]}' if s.isdigit() else '' ``` ![image](https://hackmd.io/_uploads/rkzgaCTR1e.png) ```python= def generate_n_grams(s, n): s, n_grams = s.split(), [] for i in range(len(s)-n+1): n_gram = ' '.join(s[i:i+n]) n_grams.append(n_gram) return n_grams ``` ![image](https://hackmd.io/_uploads/H1KpCA60yl.png) ```python= obfuscate_employee_id = lambda s: [i[0] + '-*****' for i in s] ``` ![image](https://hackmd.io/_uploads/rJY1gkRAyx.png) ```python= def extract_following_words(arr, kw): arr = arr.split() return [arr[i+1] for i in range(len(arr)) if arr[i]==kw] ``` ![image](https://hackmd.io/_uploads/HkdkPVyJxl.png) ```python= from re import sub cleanse_text_data = lambda arr: [sub(r'\d+', '', i) for i in arr] ``` ![image](https://hackmd.io/_uploads/SyZ4n4kylx.png) ```python= find_increase_sentences = lambda arr: list(filter(lambda x: 'increase' in x.lower(), [i.strip() for i in arr.split('.')])) ``` ![image](https://hackmd.io/_uploads/S1oAhEykxg.png) ```python= reverse_city_names = lambda arr: [i[::-1] for i in arr] ``` ![image](https://hackmd.io/_uploads/ryy6WGPyeg.png) ```python= convert_text_to_uppercase = lambda x: [i.upper() for i in x] ``` ![image](https://hackmd.io/_uploads/SkiSGzvyxx.png) ```python= calculate_total_price = lambda arr, rate: sum(arr) * (1-rate) ``` ![image](https://hackmd.io/_uploads/B1roQGP1el.png) ```python= trim_strings = lambda arr: [i.strip() for i in arr] ``` ![image](https://hackmd.io/_uploads/S1PyEGPkle.png) ```python= convert_initials = str.title ``` ![image](https://hackmd.io/_uploads/rkukBfwkgl.png) ```python= concatenate_strings_and_reverse = lambda arr: ''.join(arr[::-1]) ``` ![image](https://hackmd.io/_uploads/Sy1hBfDJel.png) ```python= check_ascii_string = lambda s: all(ord(i)<128 for i in s) ``` ![image](https://hackmd.io/_uploads/SyfiLzP1gl.png) ```python= reverse_string = lambda s: s[::-1] ``` ![image](https://hackmd.io/_uploads/H1jLvfPyge.png) ```python= check_email_domain = lambda s, d: s.lower().endswith(d.lower()) ``` ![image](https://hackmd.io/_uploads/BkyAwfPkgg.png) ```python False ``` ![image](https://hackmd.io/_uploads/B1vg_Mw1xe.png) ```python= first_last_two = lambda s: s if len(s)<4 else s[:2] + s[-2:] ``` ![image](https://hackmd.io/_uploads/ryioKGwkle.png) ```python= remove_char = lambda s, c: s.replace(c, '') ``` ![image](https://hackmd.io/_uploads/H13hcfPyee.png) ```python True ``` ![image](https://hackmd.io/_uploads/S10TcGw1lx.png) ```python= check_reorder = lambda c, r: c < r ``` ![image](https://hackmd.io/_uploads/ryYQoMDylg.png) ```python True ``` ![image](https://hackmd.io/_uploads/r1rSszvJle.png) ```python= middle_chars = lambda s: s[len(s)//2] if len(s)%2 else s[len(s)//2-1:len(s)//2+1] ``` ![image](https://hackmd.io/_uploads/SJYu_PPkle.png) ```python= convert_date = lambda d: f'{d[-2:]}-{d[4:6]}-{d[:4]}' ``` ![image](https://hackmd.io/_uploads/ry4G2Pvkll.png) ```python False ``` ![image](https://hackmd.io/_uploads/rkiB3Dvyeg.png) ```python= remove_ends = lambda s: '' if len(s)<2 else s[1:-1] ``` ![image](https://hackmd.io/_uploads/BygeawD1ex.png) ```python True ``` ![image](https://hackmd.io/_uploads/rJX76wvkeg.png) ```python= find_lowest_price = lambda s: min(map(float, s)) ``` ![image](https://hackmd.io/_uploads/H1Pg0vPJll.png) ```python False ``` ![image](https://hackmd.io/_uploads/r1m7APPyxx.png) ```python= every_other_char = lambda s: s[::2] ``` ![image](https://hackmd.io/_uploads/rkV1yuwyxl.png) ```python True ``` ![image](https://hackmd.io/_uploads/BJ7bk_P1ee.png) ```python True ``` ![image](https://hackmd.io/_uploads/HyTMJOP1lx.png) ```python True ``` ![image](https://hackmd.io/_uploads/Hy341ODkxl.png) ```python False ```