# 18Dice (6-10單元) > [name=ChiuTing] # 第六單元 單一選擇 ****6-1 及格嗎?** ```cpp a,b = map(int,input().split()) if a!=b: print(f"{a}!={b}") ``` **6-2正數** ```cpp a = int(input()) if a>0: print(f"{a}是正數") ``` **6-3偶數** ```cpp a = int(input()) if a%2==0: print(f"{a}是偶數") ``` **6-4發現不相等** ```cpp a,b = map(int,input().split()) if a!=b: print(f"{a}!={b}") ``` --- # 第七單元 用if交換變數 **7-1比大小** ```cpp a,b = map(int,input().split()) c,d = map(int,input().split()) print(f"最大值{max(a,b)}") print(f"最大值{max(c,d)}") ``` **7-2三數比大小** ```cpp a,b,c = map(int,input().split()) d,e,f = map(int,input().split()) print(f"最大值{max(max(a,b),max(a,c))}") print(f"最小值{min(min(a,b),min(a,c))}") print(f"最大值{max(max(d,e),max(d,f))}") print(f"最小值{min(min(d,e),min(d,f))}") ``` **7-3五數比大小** ```cpp list1 = list(map(int,input().split())) print(f"最大值{max(list1)}") print(f"最小值{min(list1)}") ``` --- # 第八單元 雙重選擇 **8-1及格與否** ```cpp def func(x): if x>=60: print(f"{x}分及格") else: print(f"{x}分不及格") a = int(input()) b = int(input()) func(a) func(b) ``` **8-2奇數還是偶數** ```cpp def func(x): if x%2==0: print(f"{x}是偶數") else: print(f"{x}是奇數") a = int(input()) b = int(input()) func(a) func(b) ``` **8-3是否能構成三角形** ```cpp list1 = list(map(int,input().split())) sum1 = sum(list1) if sum1-max(list1)*2>0: print(*list1, end='') print(f"可以構成三角形") else: print(*list1, end='') print(f"不可以構成三角形") list1 = list(map(int,input().split())) sum1 = sum(list1) if sum1-max(list1)*2>0: print(*list1, end='') print(f"可以構成三角形") else: print(*list1, end='') print(f"不可以構成三角形") ``` **8-4是否能構成直角三角形** ```cpp list1 = list(map(int,input().split())) list1.sort() if list1[0]*list1[0]+list1[1]**2==list1[2]**2: print("直角三角形") else: print("不是直角三角形") list1 = list(map(int,input().split())) list1.sort() if list1[0]*list1[0]+list1[1]**2==list1[2]**2: print("直角三角形") else: print("不是直角三角形") ``` **8-5是否能與7相關** ```cpp N = int(input()) if N%7==0 or (N-7)%10==0: print(f"{N}符合標準") else: print(f"{N}不符合標準") N = int(input()) if N%7==0 or (N-7)%10==0: print(f"{N}符合標準") else: print(f"{N}不符合標準") N = int(input()) if N%7==0 or (N-7)%10==0: print(f"{N}符合標準") else: print(f"{N}不符合標準") ``` **8-6拆數字** ```cpp N = list(input()) for i in range(len(N)): print(N[i]) ``` **8-7是否為3的倍數** ```cpp N = list(input()) for i in range(len(N)): N[i] = int(N[i]) if i==0: print(f"百位數{N[i]}", end='') if i==1: print(f"十位數{N[i]}", end='') if i==2: print(f"個位數{N[i]}", end='') if N[i]%3==0: print("是3的倍數") else: print("不是3的倍數") ``` **8-8是否為迴文(針)** ```cpp N1 = input() c = N1 N1 = list(N1) N2 = N1[:] N2.reverse() if N1==N2: print(f"{c}是迴文") else: print(f"{c}不是迴文") N1 = input() c = N1 N1 = list(N1) N2 = N1[:] N2.reverse() if N1==N2: print(f"{c}是迴文") else: print(f"{c}不是迴文") ``` **8-9自主學習(分數加太少不想寫)** --- # 第九單元 巢狀選擇 **9-1分數等第** ```cpp level = 0 N = int(input()) if N>=90: level = "A" elif N>=80: level = "B" elif N>=70: level = "C" elif N>=60: level = "D" else: level = "F" print(f"Your score is {N} and degree is {level}!") ``` **9-2正三角形嗎** ```cpp N1 = list(map(int,input().split())) N = N1[:] N.sort() if N[0]==N[1]==N[2]: print(f"{N1[0]} {N1[1]} {N1[2]}正三角形") elif (N[1]+N[0])>N[2]: print(f"{N1[0]} {N1[1]} {N1[2]}非正三角形") else: print(f"{N1[0]} {N1[1]} {N1[2]}無法構成正三角形") N1 = list(map(int,input().split())) N = N1[:] N.sort() if N[0]==N[1]==N[2]: print(f"{N1[0]} {N1[1]} {N1[2]}正三角形") elif (N[1]+N[0])>N[2]: print(f"{N1[0]} {N1[1]} {N1[2]}非正三角形") else: print(f"{N1[0]} {N1[1]} {N1[2]}無法構成正三角形") N1 = list(map(int,input().split())) N = N1[:] N.sort() if N[0]==N[1]==N[2]: print(f"{N1[0]} {N1[1]} {N1[2]}正三角形") elif (N[1]+N[0])>N[2]: print(f"{N1[0]} {N1[1]} {N1[2]}非正三角形") else: print(f"{N1[0]} {N1[1]} {N1[2]}無法構成三角形") ``` **9-3玩玩二分法** ```cpp def func(x): if x>0: if x>10000: return "B" return "A" else: if x<=-10000: return "C" return "D" N = int(input()) if func(N)=="A" or func(N)=="B": print(f"{N}是正數") else: print(f"{N}是負數") print(func(N)) N = int(input()) if func(N)=="A" or func(N)=="B": print(f"{N}是正數") else: print(f"{N}是負數") print(func(N)) N = int(input()) if func(N)=="A" or func(N)=="B": print(f"{N}是正數") else: print(f"{N}是負數") print(func(N)) ``` --- # 第十單元 多選一 **10-1分數等第** ```cpp N = int(input()) sco = 0 if N>=90: sco ="A" print(f"Your score is {N} and degree is {sco}!") elif N>=80: sco ="B" print(f"Your score is {N} and degree is {sco}!") elif N>=70: sco ="C" print(f"Your score is {N} and degree is {sco}!") elif N>=60: sco ="D" print(f"Your score is {N} and degree is {sco}!") else: sco ="F" print(f"Your score is {N} and degree is {sco}!") N = int(input()) sco = 0 if N>=90: sco ="A" print(f"Your score is {N} and degree is {sco}!") elif N>=80: sco ="B" print(f"Your score is {N} and degree is {sco}!") elif N>=70: sco ="C" print(f"Your score is {N} and degree is {sco}!") elif N>=60: sco ="D" print(f"Your score is {N} and degree is {sco}!") else: sco ="F" print(f"Your score is {N} and degree is {sco}!") N = int(input()) sco = 0 if N>=90: sco ="A" print(f"Your score is {N} and degree is {sco}!") elif N>=80: sco ="B" print(f"Your score is {N} and degree is {sco}!") elif N>=70: sco ="C" print(f"Your score is {N} and degree is {sco}!") elif N>=60: sco ="D" print(f"Your score is {N} and degree is {sco}!") else: sco ="F" print(f"Your score is {N} and degree is {sco}!") ``` **10-2點套餐** ```cpp N = int(input()) if N==11: print("牛奶") print("西瓜") print("檸檬水") print("吐司") elif N==22: print("西瓜") print("檸檬水") print("吐司") elif N==33: print("檸檬水") print("吐司") elif N==44: print("吐司") else: print("超出範圍") N = int(input()) if N==11: print("牛奶") print("西瓜") print("檸檬水") print("吐司") elif N==22: print("西瓜") print("檸檬水") print("吐司") elif N==33: print("檸檬水") print("吐司") elif N==44: print("吐司") else: print("超出範圍") ``` **10-3猴子上學** ```cpp N = int(input()) if N==11: print("星期一猴子穿新衣") elif N==22: print("星期二猴子肚子餓") elif N==33: print("星期三猴子去爬山") elif N==44: print("星期四猴子看電視") elif N==55: print("星期五猴子去跳舞") ``` **10-4年齡說 年輪說** https://www.youtube.com/watch?v=anurOHpo0aY 好聽ㄟ ```cpp N = int(input()) sco = N if N>=70: print(f"{sco}歲是從心所欲,不逾矩之年") elif N>=60: print(f"{sco}歲是耳順之年") elif N>=50: print(f"{sco}歲是知天命之年") elif N>=40: print(f"{sco}歲是不惑之年") elif N>=30: print(f"{sco}歲是而立之年") elif N>=15: print(f"{sco}歲志於學") elif N>=1: print(f"{sco}歲是小孩子") N = int(input()) sco = N if N>=70: print(f"{sco}歲是從心所欲,不逾矩之年") elif N>=60: print(f"{sco}歲是耳順之年") elif N>=50: print(f"{sco}歲是知天命之年") elif N>=40: print(f"{sco}歲是不惑之年") elif N>=30: print(f"{sco}歲是而立之年") elif N>=15: print(f"{sco}歲志於學") elif N>=1: print(f"{sco}歲是小孩子") N = int(input()) sco = N if N>=70: print(f"{sco}歲是從心所欲,不逾矩之年") elif N>=60: print(f"{sco}歲是耳順之年") elif N>=50: print(f"{sco}歲是知天命之年") elif N>=40: print(f"{sco}歲是不惑之年") elif N>=30: print(f"{sco}歲是而立之年") elif N>=15: print(f"{sco}歲志於學") elif N>=1: print(f"{sco}歲是小孩子") ``` **10-5三角形別** ```cpp list11 = list(map(int, input().split())) list1 = sorted(list11) ans = 0 if list1[0]==list1[1]==list1[2]: ans = "正三角形" elif list1[2]>=list1[1]+list1[0]: ans = "無法構成三角形" elif list1[1]==list1[0] or list1[1]==list1[2]: ans = "等腰三角形" else: ans = "一般三角形" print(*list11, end="") print(ans) list11 = list(map(int, input().split())) list1 = sorted(list11) ans = 0 if list1[0]==list1[1]==list1[2]: ans = "正三角形" elif list1[2]>=list1[1]+list1[0]: ans = "無法構成三角形" elif list1[1]==list1[0] or list1[1]==list1[2]: ans = "等腰三角形" else: ans = "一般三角形" print(*list11, end="") print(ans) list11 = list(map(int, input().split())) list1 = sorted(list11) ans = 0 if list1[0]==list1[1]==list1[2]: ans = "正三角形" elif list1[2]>=list1[1]+list1[0]: ans = "無法構成三角形" elif list1[1]==list1[0] or list1[1]==list1[2]: ans = "等腰三角形" else: ans = "一般三角形" print(*list11, end="") print(ans) list11 = list(map(int, input().split())) list1 = sorted(list11) ans = 0 if list1[0]==list1[1]==list1[2]: ans = "正三角形" elif list1[2]>=list1[1]+list1[0]: ans = "無法構成三角形" elif list1[1]==list1[0] or list1[1]==list1[2]: ans = "等腰三角形" else: ans = "一般三角形" print(*list11, end="") print(ans) ``` **不用了 我要去睡覺明天在貼之後的單元(q_q)** ![](https://i.imgur.com/4F0kbqP.png)
{"metaMigratedAt":"2023-06-17T12:51:02.461Z","metaMigratedFrom":"Content","title":"18Dice (6-10單元)","breaks":true,"contributors":"[{\"id\":\"1dadeef6-2273-415e-965a-cdbad185c938\",\"add\":8851,\"del\":129}]"}
Expand menu