# Python TQC 401~410 ## 401 最小值 ### 說明: 請撰寫一程式,由使用者輸入十個數字,然後找出其最小值,最後輸出最小值。 ### 輸入/輸出 範例輸入:  範例輸出:  ### Code: ```python= num = [] for i in range(10): num.append(eval(input())) print(min(num)) ``` ## 402 不定數迴圈-最小值 ### 說明: 請撰寫一程式,讓使用者輸入數字,輸入的動作直到輸入值為9999才結束,然後找出其最小值,並輸出最小值。 ### 輸入/輸出 範例輸入:  範例輸出:  ### Code: ```python= LIST = [] while True: value = eval(input()) if value == 9999: break LIST.append(value) print(min(LIST)) ``` ## 403 倍數總和計算 ### 說明: 請撰寫一程式,讓使用者輸入兩個正整數a、b(a<=b),輸出從a到b(包含a和b)之間4或9的倍數(一列輸出十個數字、欄寬為4、靠左對齊)以及倍數之個數、總和。 ### 輸入/輸出 範例輸入:  範例輸出:  ### Code: ```python= a = eval(input()) b = eval(input()) newline=1 totalsum=0 for i in range(a,b+1): if (i%4==0 or i%9==0)and newline!=10: print('%-4d'%i,end='') newline+=1 totalsum+=i elif i%4==0 or i%9==0: print('%-4d'%i) newline+=1 totalsum+=i print('\n%d'%(newline-1)) print(totalsum) ``` ## 404 數字反轉判斷 ### 說明: 請撰寫一程式,讓使用者輸入一個正整數,將此正整數以反轉的順序輸出,並判斷如輸入0,則輸出為0。 ### 輸入/輸出 範例輸入:   範例輸出:   ### Code: ```python= num = eval(input()) if num == 0: print(0) else: while(num!=0): print('%d'%(num%10),end='') num//=10 ``` ## 405 不定數迴圈-分數等級 ### 說明: 請撰寫一程式,以不定數迴圈的方式輸入一個正整數(代表分數),之後根據以下分數與GPA的對照表,印出其所對應的GPA。假設此不定數迴圈輸入9999則會結束此迴圈。標準如下表所示:  ### 輸入/輸出 範例輸入/輸出:  ### Code: ```python= num = eval(input()) while num!=9999: if 90<= num <=100: print('A') elif 80 <= num <=89: print('B') elif 70 <= num <=79: print('C') elif 60 <= num <=69: print('D') elif 0 <= num <=59: print('E') else: print('Error!') num = eval(input()) ``` ## 406 不定數迴圈-BMI計算 ### 說明: 請撰寫一程式,以不定數迴圈的方式輸入身高與體重,計算出BMI之後再根據以下對照表,印出BMI及相對應的BMI代表意義(State)。假設此不定數迴圈輸入-9999則會結束此迴圈。 > 輸出浮點數到小數點後第二位。 >  > 標準如下表所示: >  ### 輸入/輸出 範例輸入/輸出:  ### Code: ```python= height = eval(input()) while height != -9999: weight = eval(input()) if weight != -9999: bmi = weight/(pow(height/100,2)) print('BMI:%.2f'%bmi) if bmi < 18.5: print('State:under weight') elif 18.5 <= bmi <25: print('State:normal') elif 25 <= bmi <30: print('State:over weight') elif 30 <= bmi: print('State:fat') else: break height = eval(input()) ``` ## 407 不定數迴圈-閏年判斷 ### 說明: 1. 請撰寫一程式,以不定數迴圈的方式讓使用者輸入西元年份,然後判斷它是否為閏年(leap year)或平年。其判斷規則如下:每四年一閏,每百年不閏,但每四百年也一閏。 2. 假設此不定數迴圈輸入-9999則會結束此迴圈。 ### 輸入/輸出 範例輸入/輸出:  ### Code: ```python= year = eval(input()) while year!=-9999: if year%400==0: print('%d is a leap year.'%year) elif year%100==0: print('%d is not a leap year.'%year) elif year%4==0: print('%d is a leap year.'%year) else: print('%d is not a leap year.'%year) year = eval(input()) ``` ## 408 奇偶數個數計算 ### 說明: 請撰寫一程式,讓使用者輸入十個整數,計算並輸出偶數和奇數的個數。 ### 輸入/輸出 範例輸入:  範例輸出:  ### Code: ```python= oddcount=0 evencount=0 for i in range(10): num = eval(input()) if num%2==0: evencount+=1 else: oddcount+=1 print('Even numbers: %d'%evencount) print('Odd numbers: %d'%oddcount) ``` ## 409 得票數計算 ### 說明: 某次選舉有兩位候選人,分別是No.1: Nami、No.2:Chopper。請撰寫一程式,輸入五張選票,輸入值如為1即表示針對1號候選人投票;輸入值如為2即表示針對2號候選人投票,如輸入其他值則視為廢票。每次投完後需印出目前每位候選人的得票數,最後印出最高票者為當選人;如最終計算有相同的最高票數者或無法選出最高票者,顯示【=> No one wonthe election.】。 ### 輸入/輸出 範例輸入/輸出:  ### Code: ```python= vote1 = vote2 = votenull = 0 for i in range(5): vote = eval(input()) if vote == 1: vote1+=1 elif vote == 2: vote2+=1 else: votenull+=1 print('Total votes of NO.1:Nami = %d'%vote1) print('Total votes of NO.2:Chopper = %d'%vote2) print('Total null votes = %d'%votenull) if vote1 > vote2: print('No.1 Nami won the election.') elif vote2 > vote1: print('No.2 Chopper won the election.') else: print('No one won the election.') ``` ## 410 繪製等腰三角形 ### 說明: 請撰寫一程式,依照使用者輸入的n,畫出對應的等腰三角形。 ### 輸入/輸出 範例輸入:  範例輸出:  ### Code: ```python= n = eval(input()) for i in range(1,n+1): for j in range(0,n-i): print(' ',end='') for k in range((2*i)-1): print('*',end='') print() ``` --- 相關文章: ###### tags: `python`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up