# GenAIEd Python 解答
:::info
此篇筆記為[GenAIEd](https://edaitutor.com/en/course)網站之解答,解答在題目擷圖之下方
由於每個帳號的題目順序不同,此篇筆記以作者帳號之題目順序為主
如有錯誤、不懂、想交流程式、想學 Python 者,請聯繫我
>作者:蔡淳宇 @Chuen666666
>LINE:chuen666666
>Discord:chuen666666
:::
## Module 1 什麼是「資訊管理」:資訊科技的商管應用

```python
True
```

```python
True
```
## Module 2 Python 程式設計初探

```python
True
```

```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')
```

```python=
print(int(input()) * int(input()) // 500)
```

```python=
print(*divmod(int(input()), 12))
```

```python=
d = int(float(input()) * int(input())*24*60*60)
print(d, *divmod(d, 150000000), sep='\n')
```

```python=
s = int(input())
m, s = divmod(s, 60)
h, m = divmod(m, 60)
print(f'{h}:{m}:{s}')
```

```python=
q, p = int(input()), int(input())
print(f'({p*q}, {p*q*0.1}, {round(p*q*1.1, 5)})')
```

```python=
print(int((int(input())*int(input())*int(input())*int(input())*0.75)//1000))
```

```python=
print(int(input()) >= 50, 2, sep='\n')
```

```python=
print(int(input()) * int(input()), 3, sep='\n')
```

```python
True
```

```python
False
```

```python
False
```

```python
False
```

```python
True
```

```python
False
```

```python
True
```

```python
True
```

```python
False
```

```python=
p, i, n = int(input()), int(input()), int(input())
print(int(p*(1+i/100)**n))
```

```python=
print(int(input())*int(input())+50)
```

```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)
```

```python=
print(int(input()) * float(input()))
```

```python=
print(int(input()) > int(input()), 3, sep='\n')
```

```python=
print(int(input()) * float(input()))
```

```python=
print(float(input())*12 + float(input())*1.5)
```

```python=
print(int(((4/3)*3.14*float(input())**3) * int(input())))
```

```python=
print(abs(100 - int(input())))
```

```python=
print(int(input()) * int(input()), 3, sep='\n')
```

```python=
print(int(input()) ** 2)
```

```python=
print(int(input()) + int(input()))
```

```python=
print(int(input())*int(input()) + int(input())*int(input()), 6, sep='\n')
```

```python=
total = 0
for _ in range(7):
total += int(input())
print(total, 8, sep='\n')
```

```python=
print(int(input()) + int(input()))
```

```python=
print(int(input()) + int(input()))
```

```python=
a, b = int(input()), int(input())
print(a+b, a-b, a*b, a//b, a%b, a**b, sep='\n')
```

```python=
print(int(input()) + int(input()) + int(input()), 4, sep='\n')
```

```python=
print(round((int(input())+int(input())) * (1+int(input())/100), 1), 4, sep='\n')
```

```python=
print(int(input()) * int(input()))
```

```python=
print((int(input())*int(input()) + int(input())*int(input())) * 120, 5, sep='\n')
```
## Module 3 「電腦運作基本原理」與「條件式選擇」(一)

```python
True
```

```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')
```

```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')
```

```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')
```

```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)
```

```python=
tp = input()
print(4200.0 if tp=='Manager' else 3605.0 if tp=='Developer' else 2000.0 if tp=='Intern' else 0.0)
```

```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')
```

```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')
```

```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)
```

```python=
print('Yes' if input()=='5' else 'No', 3, sep='\n')
```

```python
True
```

```python
True
```

```python
False
```

```python
False
```

```python
True
```

```python
False
```

```python
False
```

```python
False
```

```python
True
```

```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')
```

```python=
print('Brewing coffee...' if input()=='Coffee' else 'No coffee right now.', 2, sep='\n')
```

```python=
print(float(input())*int(input())+float(input()))
```

```python=
print((100-float(input()))/100 * float(input()))
```

```python=
print(float(input()) + float(input()) + float(input()))
```

```python=
a = int(input())
print('Negative' if a<0 else 'Positive' if a>0 else 'Zero', 5, sep='\n')
```

```python=
print(int(input()) + int(input()))
```

```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')
```

```python=
print(round(int(input())+float(input()), 1))
```

```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')
```

```python=
print(int(input())>=18 and int(input())>=5)
```

```python=
print(f'Account Number: {input()}, Balance: ${int(float(input()))}')
```

```python=
print(round(float(input())*(1+float(input())), 1))
```

```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')
```

```python=
n = int(input())
print(f'Double is {n*2}\n{"It is zero." if n==0 else "Not zero."}\n4')
```

```python=
m = float(input())
print(m*0.9 if m>500 else m*0.95)
```

```python=
print(int(float(input())))
```

```python=
p = float(input()) * int(input())
print(round(p*0.9 if p>100 else p, 1))
```

```python=
print(float(input()+input()))
```

```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')
```

```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「電腦運作基本原理」與「條件式選擇」(二)

```python
True
```

```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')
```

```python=
amm, saf = int(input()), int(input())
print('需要緊急補貨' if amm<saf/2 else '需要補貨' if amm<saf else '不需要補貨')
```

```python=
age = int(input())
print('可以投票' if age >= 20 else f'還需{20-age}年才可以投票')
```

```python=
a = [int(input()) for i in range(3)]
a.sort()
if a[0]**2 + a[1]**2 != a[2]**2:
print('不', end='')
print('符合畢氏定理')
```

```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 '')
```

```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))
```

```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)
```

```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''')
```

```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')
```

```python
True
```

```python
True
```

```python
False
```

```python
False
```

```python
False
```

```python
True
```

```python
False
```

```python
True
```

```python
True
```

```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")
```

```python=
t = int(input())
print('早安' if 0<=t<12 else '午安' if 12<=t<18 else '晚安')
```

```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(',關鍵銷售額')
```

```python=
t = int(input())
print('VIP顧客' if t>=20 else '忠實顧客' if t>=10 else '普通顧客')
```

```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')
```

```python=
make, goal = int(input()), int(input())
print('超過目標200%' if make>=goal*2 else '達到目標' if make>=goal else '未達到目標')
```

```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))
```

```python=
sco, sta = int(input()), int(input())
print('達到優秀標準' if sco>=sta*1.2 else '達到標準' if sco>=sta else '未達到標準')
```

```python=
s = int(input())
print('優秀' if s>=90 else '高於平均' if s>=70 else '低於平均')
```

```python=
a, g = int(input()), int(input())
print('超過目標120%' if a>g*1.2 else '達成目標' if a>=g else '未達成目標')
```

```python=
a, b = int(input())*int(input()), int(input())
print('達到最低收入標準' if a>=b else '未達到最低收入標準')
```

```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")
```

```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
```

```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))
```

```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")
```

```python=
t = float(input())
print('熱' if t>30 else '冷' if t<15 else '涼')
```

```python=
a = int(input())
print('符合退休條件' if a>=30 else '符合晉升條件' if a>=5 else '不符合條件')
```

```python=
a, b = int(input()), int(input())
print('員工A月薪更高' if a>b else '員工B月薪更高' if a<b else '兩者月薪相等')
```

```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 '一般')
```

```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 "奇"}數')
```

```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 迴圈(上)

```python
True
```

```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')
```

```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}')
```

```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}')
```

```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}')
```

```python=
s = 0
for _ in range(int(input())):
s += float(input())
print(s)
```

```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')
```

```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}')
```

```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}')
```

```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")
```

```python
False
```

```python
False
```

```python
False
```

```python
False
```

```python
False
```

```python
False
```

```python
True
```

```python
False
```

```python
False
```

```python=
n = int(input())
print(n//2 if n%2==0 else n//2+1)
```

```python=
m, t = int(input()), 0
while m >= 50:
m -= 50
t += 1
print(m)
print(f'Total months: {t}')
```

```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')
```

```python=
from math import factorial
print(factorial(int(input())))
```

```python=
print(*range(int(input()))[::-1], 'Inventory depleted', sep='\n')
```

```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')
```

```python=
print(int(input()) * 40)
```

```python=
print(int(input()) * 8)
```

```python=
print(sum(i for i in range(1, int(input())+1) if i%2==0))
```

```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")
```

```python=
for i in range(int(input()), 0, -1):
print(i if i%3 else 'Boom!')
print('Blast off!')
```

```python=
t = 0
while True:
a = input().upper()
if a == '#': break
if a in ('A', 'E', 'I', 'O', 'U'):
t += 1
print(t)
```

```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')
```

```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
```

```python=
n = int(input())
print(n//5 if n%5==0 else n//5+1)
```

```python=
a = divmod(int(input()), 4)
print(f'Complete groups: {a[0]}\nRemaining students: {a[1]}')
```

```python=
n = int(input())
print((n+1)*n // 2)
```

```python=
print(int(input()) * 5)
```

```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')
```

```python=
for i in range(int(input()), 0, -1):
print(i)
print('Liftoff!')
```

```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 迴圈(下)

```python
False
```

```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")
```

```python=
n = 0
for i in range(1, int(input())+1):
n += i * 80
print(n)
```

```python=
n = int(input())
for i in range(n):
print('*'*n if i==0 or i==n-1 else '*'+' '*(n-2)+'*')
```

```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)
```

```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)
```

```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)
```

```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')
```

```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)
```

```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')
```

```python
False
```

```python
True
```

```python
False
```

```python
False
```

```python
False
```

```python
False
```

```python
True
```

```python
True
```

```python
False
```

```python
n = int(input())
for i in range(1, 11):
print(n * i)
```

```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')
```

```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))
```

```python=
print(int(input()) * 5)
```

```python=
t = 0
for _ in range(int(input())):
t += int(input())
print(t)
```

```python=
t = 0
for i in range(1, int(input())+1):
for j in range(1, 4):
t += i * j * 2
print(t)
```

```python=
t = 0
for i in range(1, int(input())+1):
t += i
print(t)
```

```python=
for i in range(1, int(input())+1):
print(i ** 2)
```

```python=
print(int(input()) / 2)
```

```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')
```

```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')
```

```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')
```

```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')
```

```python=
print(int(input()) ** 2)
```

```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)
```

```python=
n = 0
for _ in range(int(input())):
if int(input()) >= 60: n += 1
print(n)
```

```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')
```

```python=
t, s = 0, int(input())
for _ in range(8):
t += s
s += 5
print(t)
```

```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)
```

```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)
```

```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 清單

```python
False
```

```python
True
```

```python=
print(min(map(int, input().split())))
```

```python=
a = list(map(int, input().split()))
a.append(sum(a))
print(a[::-1])
```

```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}')
```

```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')
```

```python=
a = list(map(int, input().split()))
b = [i for i in a if i > sum(a)/len(a)]
b.sort()
print(b)
```

```python=
arr, t = [], 0
for i in map(int, input().split()):
t += i
arr.append(t)
print(arr)
```

```python=
print(list(map(lambda x: x*2 if x%2==0 else x, map(int, input().split()))))
```

```python=
a = list(map(int, input().split()))
print(list(map(lambda x: x+5, a)), a, 5, sep='\n')
```

```python=
ids = input().split()
ids = [int(x) for x in ids if int(x) % 2]
print(ids[::-1], 5, sep='\n')
```

```python=
sales = list(set(map(int, input().split())))
sales.sort()
print(sales, 7, sep='\n')
```

```python=
a = list(map(int, input().split()))
a.remove(min(a))
a.remove(max(a))
print(a, 7, sep='\n')
```

```python=
a = list(map(int, input().split()))
print(list(map(lambda x: x+1, a)), a, 5, sep='\n')
```

```python=
import re
print(list(map(int, re.split(r'[ ,]', input()))))
```

```python=
a = tuple(map(float, input().split()))
print(round(sum(a)/len(a), 2))
```

```python=
a = list(map(float, input().split()))
print([sum(a)] + a + [round(sum(a)/len(a), 1)])
```

```python=
print(list(map(lambda x: x*2, map(int, input().split()))))
```

```python=
print(list(map(int, input().split()))[::-1])
```

```python=
print(list(map(lambda x:x+1, map(int, input().split()))))
```

```python
True
```

```python
False
```

```python=
a = list(map(int, input().split())) + list(map(int, input().split()))
a.sort()
print(a, 4, sep='\n')
```

```python=
print([i for i in map(int, input().split()) if i%2==0])
```

```python
True
```

```python=
print(sum(i for i in map(int, input().split()) if i>=50), 6, sep='\n')
```

```python
True
```

```python
False
```

```python
False
```

```python=
a = list(map(int, input().split()))
print([] if len(a)<3 else a[1:-1])
```

```python=
a = list(map(int, input().split()))
print([a[-1]]+a[1:-1]+[a[0]] if len(a)>1 else a, 5, sep='\n')
```

```python=
print(round(sum(map(float, input().split())), 1))
```

```python=
a = input().split(';')
a.sort()
print(a)
```

```python=
print(list(map(int, input().split()))[1:-1][::-1], 3, sep='\n')
```

```python
False
```

```python=
print([input().title() for _ in range(int(input()))])
```

```python=
a = list(map(int, input().split(',')))
a.sort()
print(a)
```

```python
False
```

```python=
print(max(map(float, input().split(','))))
```

```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 作業管理與演算法應用

```python
True
```

```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)
```

```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)
```

```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)
```

```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]))
```

```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)
```

```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')
```

```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")
```

```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')
```

```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")
```

```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')
```

```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')
```

```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=' ')
```

```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))
```

```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)
```

```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=' ')
```

```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)
```

```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)
```

```python
True
```

```python
False
```

```python=
print(int(input()) - sum(map(int, input().split())))
```

```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)
```

```python=
print(sum(map(int, input().split())))
```

```python
False
```

```python=
init = int(input())
t = 0
for i in map(int, input().split()):
init -= i
if init < 0:
init += 300
t += 1
print(t)
```

```python=
n = int(input())
print(n > 0 and (n & (n-1)) == 0)
```

```python=
cost, q, s = int(input()), int(input()), sum(map(int, input().split()))
print(cost*s//2 if s>q else cost*s)
```

```python
True
```

```python
True
```

```python=
a, b, c = int(input()), int(input()), int(input())
print(a+c if a<=b else a)
```

```python
True
```

```python
True
```

```python
False
```

```python
True
```

```python
False
```

```python
True
```

```python
True
```

```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))
```

```python=
need, w, arr = int(input()), int(input()), tuple(map(int, input().split()))
print(max(0, need+arr[-1]-w))
```

```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 (上)

```python
True
```

```python=
calculate_total_inventory_value = lambda p, q: sum(p*i for i in q)
```

```python=
calculate_discount_price = lambda p, d: round(p * (1-d/100), 2)
```

```python=
def days_to_finish_book(ttl, start, step):
t = now = 0
while now < ttl:
t += 1
now += start
start += step
return t
```

```python
False
```

```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
```

```python=
max_ad_profit = lambda arr, n1, n2: sum(arr[:min(n1, n2)])
```

```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
```

```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
```

```python=
calculate_depreciation = lambda val, rt, y: val * ((1-rt/100)**y)
```

```python=
can_graduate = lambda a, b, c: (a>=70 and b<5 and c<3) or (a>90)
```

```python=
calculate_salary = lambda b, hr, y=0: round(b + max(0, hr-160)*(b/160)*1.5 + b*0.05*y)
```

```python=
calculate_total_payroll = lambda arr: sum(i[0]*i[-1] for i in arr)
```

```python=
calculate_discounted_price = lambda p, d: sum(p) * (1-d)
```

```python=
calculate_total_price = lambda n, p=10: n * p
```

```python=
calculate_optimal_revenue = lambda arr: sum(i[0]*(1-i[-1]/100) for i in arr)
```

```python
False
```

```python=
calculate_tax = lambda t: t*0.03 if t<10000 else t*0.05 if t>20000 else t*0.04
```

```python
False
```

```python
False
```

```python=
promo_calculator = lambda p, q, d: p * q * (1-d/100)
```

```python=
calculate_order_cost = lambda p, r: p * (1+r/100)
```

```python
True
```

```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)
```

```python
False
```

```python
False
```

```python
True
```

```python=
calculate_total_cost = lambda p, q: p * q * (1 if q<=10 else 0.9)
```

```python=
calculate_discount = lambda p: 0.0 if p<100 else 5.0 if p<=500 else 10.0
```

```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 (下)

```python
False
```

```python=
calculate_total_with_discount = lambda n, d: round(1.2 * n * (1-d/100), 2)
```

```python=
calculate_total = lambda arr1, arr2: sum(arr1[i]*arr2[i] for i in range(len(arr1))) if len(arr1)==len(arr2) else -1
```

```python=
apply_discount = lambda arr, d: [i*(1-d/100) for i in arr]
```

```python=
allocate_inventory = lambda a1, a2: [max(0, a1[i]-a2[i]) for i in range(len(a1))]
```

```python=
calculate_total_revenue = lambda a: sum(i[-1] for i in a)
```

```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
```

```python=
compute_discounted_price = lambda op, dp: round(op - (op*dp/100), 2)
```

```python=
calculate_bulk_discount = lambda q, d: round(q * 2.5 * (0.9 if q>=d else 1), 2)
```

```python=
calculate_cost_with_tax = lambda p, r: round(p * (1+r/100), 2)
```

```python=
find_sales_bounds = lambda arr: (round(min(arr), 2), round(max(arr), 2))
```

```python=
calculate_multiple_purchases = lambda q, p: round(sum(i * p for i in q), 2)
```

```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
```

```python=
calculate_total_costs = lambda a1, a2: [] if len(a1)!=len(a2) else [a1[i]*a2[i] for i in range(len(a1))]
```

```python
True
```

```python
False
```

```python
False
```

```python
True
```

```python
False
```

```python=
calculate_average_price = lambda arr: round(sum(arr) / len(arr), 2)
```

```python
True
```

```python
True
```

```python
True
```

```python=
calculate_total_amount = lambda n: n * 1.2
```

```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)
```

```python
True
```

```python
True
```

```python
True
```

```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

```python
True
```
## Module 11 字串String

```python
True
```

```python=
def merge_sorted_strings(arr1, arr2):
arr = arr1 + arr2
arr.sort()
return arr
```

```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)
```

```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
```

```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
```

```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))
```

```python=
validate_string_inputs = lambda arr: [i.isalpha() for i in arr]
```

```python=
convert_date_format = lambda s: f'{s[4:]}-{s[:2]}-{s[2:4]}' if s.isdigit() else ''
```

```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
```

```python=
obfuscate_employee_id = lambda s: [i[0] + '-*****' for i in s]
```

```python=
def extract_following_words(arr, kw):
arr = arr.split()
return [arr[i+1] for i in range(len(arr)) if arr[i]==kw]
```

```python=
from re import sub
cleanse_text_data = lambda arr: [sub(r'\d+', '', i) for i in arr]
```

```python=
find_increase_sentences = lambda arr: list(filter(lambda x: 'increase' in x.lower(), [i.strip() for i in arr.split('.')]))
```

```python=
reverse_city_names = lambda arr: [i[::-1] for i in arr]
```

```python=
convert_text_to_uppercase = lambda x: [i.upper() for i in x]
```

```python=
calculate_total_price = lambda arr, rate: sum(arr) * (1-rate)
```

```python=
trim_strings = lambda arr: [i.strip() for i in arr]
```

```python=
convert_initials = str.title
```

```python=
concatenate_strings_and_reverse = lambda arr: ''.join(arr[::-1])
```

```python=
check_ascii_string = lambda s: all(ord(i)<128 for i in s)
```

```python=
reverse_string = lambda s: s[::-1]
```

```python=
check_email_domain = lambda s, d: s.lower().endswith(d.lower())
```

```python
False
```

```python=
first_last_two = lambda s: s if len(s)<4 else s[:2] + s[-2:]
```

```python=
remove_char = lambda s, c: s.replace(c, '')
```

```python
True
```

```python=
check_reorder = lambda c, r: c < r
```

```python
True
```

```python=
middle_chars = lambda s: s[len(s)//2] if len(s)%2 else s[len(s)//2-1:len(s)//2+1]
```

```python=
convert_date = lambda d: f'{d[-2:]}-{d[4:6]}-{d[:4]}'
```

```python
False
```

```python=
remove_ends = lambda s: '' if len(s)<2 else s[1:-1]
```

```python
True
```

```python=
find_lowest_price = lambda s: min(map(float, s))
```

```python
False
```

```python=
every_other_char = lambda s: s[::2]
```

```python
True
```

```python
True
```

```python
True
```

```python
False
```