2016年9月9日 星期五

python 程式設計50題測試範例-47

47、試依照下列的條件設計考生成績分配狀況的條形圖。
   (1) 成績共區分為十個等級,從091019202930394049
     505960697079808990100
   (2) 輸出的形式如下圖所示,一*號代表1個人,一個@號代表5個人
     ,同一等級以不超過50人為條件。
   (3) 當輸入資料為999時代表資料的完了。
       00--09 **  2
       10--19 **** 4
       20--29 @*  6
        30--39 @  5
       40--49 @****   9
       50--59 @@****  14
        60--69 @@@@**  22
       70--79 @@@*  16
       80--89 @*  6
       90--100 ****  4

   (4)測試用的輸入資料為:
       72,81,54,68,75,42,85,60,27,66,79,32,94,6,45,83,67,61,38,65,72,56,
       67,15,90,72,67,53,48,79,42,65,72,58,100,75,67,82,52,65,72,45,82,
       75,35,75,68,50,12,78

程式:
#coding=utf8

print("47、試依照下列的條件設計考生成績分配狀況的條形圖。")
print("   (1) 成績共區分為十個等級,從0至9,10至19,20至29,30至39,40至49,")
print("     50至59,60至69,70至79,80至89,90至100。")
print("   (2) 輸出的形式如下圖所示,一個*號代表一個人,五人請顯示@ ")
print("     ,同一等級以不超過50人為條件。")
print("   (3) 當輸入資料為999時代表資料的完了。")
print("==========================================================================")


scores = [72,81,54,68,75,42,85,60,27,66,
          79,32,94, 6,45,83,67,61,38,65,
          72,56,67,15,90,72,67,53,48,79,
          42,65,72,58,100,75,67,82,52,65,
          72,45,82,75,35,75,68,50,12,78]

titles = ['  0至 9' ,' 10至19',' 20至29',' 30至39',' 40至49',' 50至59',' 60至69',' 70至79',' 80至89','90至100']


ichart=[0,0,0,0,0,0,0,0,0,0]

for i in range(0,len(scores)):
   #print (scores[i])  for debug test 除錯測試
   test=scores[i]         
   if  (test>=0 and test<=9):
       ichart[0]=ichart[0]+1
   elif (test>=10 and test<=19):
       ichart[1]=ichart[1]+1    
   elif (test>=20 and test<=29):
       ichart[2]=ichart[2]+1
   elif (test>=30 and test<=39):
       ichart[3]=ichart[3]+1       
   elif (test>=40 and test<=49):
       ichart[4]=ichart[4]+1       
   elif (test>=50 and test<=59):
       ichart[5]=ichart[5]+1       
   elif (test>=60 and test<=69):
       ichart[6]=ichart[6]+1       
   elif (test>=70 and test<=79):
       ichart[7]=ichart[7]+1       
   elif (test>=80 and test<=89):
       ichart[8]=ichart[8]+1       
   elif (test>=90 and test<=100):
       ichart[9]=ichart[9]+1       

for i in range(0,len(ichart)):
   print(titles[i],"==>",end="")         
   i1=(ichart[i]//5)    # 整除 
   i2=(ichart[i]%5)      # 餘數
   if (i1==0 and i2==0) :
       print(end="")
   elif (i1 !=0 and i2==0):
       print(i1*"@",end="")
   elif (i1==0 and i2 != 0):
       print(i2*"*",end="")        
   else:
       print((i1*"@"),i2*"*",end="")
       
   print ("==>",ichart[i])  #for debug test 除錯測試   




   

結果:

================= RESTART: D:/程式語言 Python 入門/50題/Ex50-47.py =================
47、試依照下列的條件設計考生成績分配狀況的條形圖。
   (1) 成績共區分為十個等級,從0至9,10至19,20至29,30至39,40至49,
     50至59,60至69,70至79,80至89,90至100。
   (2) 輸出的形式如下圖所示,一個*號代表一個人,五人請顯示@ 
     ,同一等級以不超過50人為條件。
   (3) 當輸入資料為999時代表資料的完了。
==========================================================================
  0至 9 ==>*==> 1
 10至19 ==>**==> 2
 20至29 ==>*==> 1
 30至39 ==>***==> 3
 40至49 ==>@==> 5
 50至59 ==>@ *==> 6
 60至69 ==>@@ **==> 12
 70至79 ==>@@ **==> 12
 80至89 ==>@==> 5
90至100 ==>***==> 3
>>> 

沒有留言:

張貼留言

2024產專班 作業2

 2024產專班 作業2   1. 系統圖       ESP32+MFRC522 組成RFID Reader 可以將RFID卡片的UID 透過 MQTT協定    上傳(發行 主題 (:topic) alex9ufo/2024/RFID/RFID_UID  ,, Payload...