# 林易初 ## 自我介紹 高三 沒有程式基礎 從0開始學 原先希望自己參加這個營隊後可以對程式有基礎認識,目的地有達到。 有學到一些不錯的程式。 ## 感想心得 雖然高中課程有上一點程式,但是大多沒在聽或是有聽沒有懂,利用這次機會我重新認識了一次python的基礎。滿有收穫的。 ## 有趣程式 ```python= **n=int(input()) if n<=10: print(n6) elif 11<=n<=20: print(60+(n-10)2) elif 21<=n<=40: print(80+(n-20)1) elif 41<=n: print(100)* ``` 這題滿簡單的 ## 寫過的程式 a001 ```python= s = input() print("hello,",s) ``` ```python= x = int(input('x = ')) y = int(input('y = ')) print("x+y =",x+y) ``` a002 ```python= a,b = input().split() # 將輸入兩個整數切割出來 print(int(a)+int(b)) # 相加前記得將字串轉成整數 ``` a006 ```python= #輸入 a,b,c = input().split() a,b,c = int(a),int(b),int(c) #處理, 輸出 d = b*b-4*a*c if d>0: d=int(d**0.5) x1,x2 = (-b+d)//(2*a),(-b-d)//(2*a) print('Two different roots x1=',x1,' , x2=',x2,sep='') elif d==0: x1 = (-b)//(2*a) print('Two same roots x=',x1,sep='') else: print('No real root') ``` d548 ```python= # 輸入 a,b = input().split() a,b = int(a),int(b) # 處理 n = (b//2-a//2)+1-(a%2) # 輸出 print(n) ``` a005 ```python= t = int(input()) for i in range(t): # 輸入 a,b,c,d = input().split() a,b,c,d = int(a),int(b),int(c),int(d) # 處理 if b-a==c-b and c-b==d-c: print('等差') else: print('等比') # 輸出 ``` a003 ```python= m,d = input().split() m,d = int(m),int(d) r = (m*2+d)%3 if r==0: print('普通') elif r==1: print('吉') else: print('大吉') ``` a021 ```python= a,op,b = input().split() a,b = int(a),int(b) if op=='+': c = a+b elif op=='-': c = a-b elif op=='*': c = a*b elif op=='/': c = a//b else: c = 'error' print(c) ``` ```python= for i in range(1,10): for j in range(i): print(i,end='') print() ``` a024 ```python= a,b=input('求a,b最大公因數').split() a,b=int(a),int(b) r=a%b while r!=0: a=b b=r r=a%b print('gcd = ',b) ``` a004 ```python= import sys for s in sys.stdin: s = int(s) if (s%4==0 and s%100!=0) or s%400==0: print('閏年') else: print('平年') ``` a058 ```python= n = int(input()) c0 = c1 = c2 = 0 for i in range(n): x = int(input()) if x%3==0: c0+= 1 elif x%3==1: c1+= 1 else: c2+= 1 print(c0,c1,c2) ``` a053 ```python= import sys for st in sys.stdin: n = int(st) if n<=10: s = n*6 elif n<=20: s = 60+(n-10)*2 elif n<=40: s = 80+(n-20) else: s = 100 print(s) ``` a02(經典) ```python= # 0.前處理 - 身分證英文字母對應 idn = [10,11,12,13,14,15,16,17,34,18,19,20,21,22,35,23,24,25,26,27,28,29,32,30,31,33] # 1.輸入 s = input() # 2.處理 sum = 0 #記得給初值 # 2-1 處理英文字母 a = idn[ord(s[0])-ord('A')] #英文轉數字 sum = sum+(a%10)*9+(a//10) # 2-2 處理中間8個數字 for i in range(1,9): sum = sum+int(s[i])*(9-i) # 2-3 處理最後一個數字 sum+= int(s[9]) # 3.輸出 if sum%10==0: print('real') else: print('fake') ``` ```python= ef c2f(tc): tf =32+1.8*tc return tf def f2c(tf): tc=(tf-32)/1.8 return tc t1 =c2f(100) print('100 度C =',t1,'度F') t2 = f2c(100) print('100 度F =',t1,'度C') ``` ```python= def m2fi(m): h=int(m/0.0254) f,i = h//12,h%12 return f,i def fi2m(f,i): return(12*f+1)*0.0254 fx,ix=m2fi(1.8) print('1米8 =',fx,'英呎',ix,'英吋') mx = fi2m(6,2) print(6,'英呎',2,'英吋',mx,'米') ``` ```python= def fac1(n): p=1 for i in range(n,0,-1): p*=i return p def fac2(n): if n==1: return 1 else: return n*fac2(n-1) n = int(input('Find n!,input n: ')) print(n,'! = ',fac1(n),sep='') print(n,'! = ',fac1(n),sep='') ``` 費事數列(經典)) ```python= # 0: 預備區 (函數定義或預先準備資料) def fib(n): if n==0: return 0 elif n==1: return 1 else: return fib(n-1)+fib(n-2) # 1: 輸入 # 2: 處理 for i in range(25): print(fib(i),end=', ') print('...') # 3: 輸出 ``` a010 ```python= # 預備區 (n有c個d的因數, d^c) def divide(d): global n c = 0 while n%d==0: n = n//d c = c+1 return c # 輸入 n = int(input()) # 處理與輸出 d = 2 # 從2開始檢查質因數 while n>1 and d<10000: e = divide(d) #檢測n可被幾個d整除, 0個(e==0)表不整除 if e>0: # 質因數抽掉後,其倍數都不會被 n 整除 if e>1: # 有指數 print(d,'^',e,sep='',end='') else: # 只有1次方 print(d,end='') if n>1: # 尚有 n print(' * ',end='') d+= 1 if n>1: print(n) else: print() ``` ### 兩個老師很不錯 ### end ###