因為是開卷期末結題測驗,所以核心代碼,后期再補充
期末測驗
- 一丶試題題目
- 二丶試題代碼
- 三丶運行結果
- ——山重水復疑無路,柳暗花明又一村——
一丶試題題目
(一)試題要求
1、完成以下程式的設計:某體操比賽共有10名運動員參加,12名評委將根據運動員表現進行評分(滿分10分),請撰寫Python程式,解決下列問題:
1)每個運動員評分中去掉一個最高分和一個最低分,計算平均成績,然后給出運動員排名;
2)盡量減少人為因素,組委會要求去掉第一個問題中打最高分或最低分次數排名前二的評委給每個運動員的評分,然后計算平均成績后排名,
(二)測驗資料,保存本地txt檔案
8.9 9.3 7.9 9.0 8.8 6.5 8.4 6.6 8.2 9.1 9.2 8.8
9.0 7.8 8.7 8.9 9.0 7.6 8.1 6.5 9.6 7.7 6.9 7.5
5.8 7.4 5.3 7.3 9.1 7.9 6.7 6.8 7.8 8.0 7.6 8.1
9.0 7.9 8.3 9.2 7.8 9.2 6.4 6.9 5.8 7.7 8.2 9.0
9.0 8.6 6.9 7.5 5.8 8.6 7.4 6.8 8.4 7.8 9.2 6.7
7.5 9.7 8.9 9.6 7.8 6.5 7.1 8.0 6.6 8.0 8.5 8.9
8.7 7.9 8.8 9.2 7.6 9.1 6.8 9.0 7.8 9.4 8.3 9.2
8.9 7.8 8.7 8.6 8.5 7.4 6.5 9.4 7.7 8.9 6.9 8.4
7.8 8.5 7.6 6.6 8.7 7.8 9.5 7.8 9.9 7.3 8.9 7.7
8.9 7.9 8.8 9.0 7.9 9.2 8.7 8.7 8.9 7.9 8.7 7.7
二丶試題代碼
# 專案名稱:
# 專案簡介:
# 作 者:key
# 開發時間:2020/12/15 19:28
"""
3. 從檔案中取出12個裁判員為10個運動員大的分數,
2).盡量減少人為因素,組委會要求去掉第一個問題中打最高分或最低分次數排名前二的評委給每個運動員的評分,然后計算平均成績后排名,
"""
from collections import Counter
import copy
import numpy as np
# 為了減少失誤,這里采用全域變數
fpath = "C:/Users/Lenovo/Desktop/dafen.txt"
# fpath = "C:/Users/Administrator/Desktop/dafen.txt"
judge = [x for x in range(1, 13)]
maxl = [] # 儲存打最高分的評委的次數
minl = [] # 存盤打最低分的評委的次數
player = [] # 原始成績資料
num = ['一','二','三','四','五','六','七','八','九','十']
# 設定樣式
strx = '-----------------------------------------------------------------------------------------------'
str1 = '------------------------------去掉最高分和最低分計算平均分-降序--------------------------------------'
str2 = '------------------------------去掉打最高最低分次數最多的前2位評委-計算平均分-降序-----------------------'
str3 = '------------------------------顯示打最高分次數的評委-----------------------------------------------'
str4 = '------------------------------顯示打最低分次數的評委-----------------------------------------------'
with open(fpath, 'r') as f:
def maxminJudge(maxmin):
def showMax(maxl):
def showMin(minl):
def questionOne():
def questionTwo(ll):
def showMeau():
def main():
# 設定判定條件
isgo = 'Y'
while isgo == 'y' or isgo == 'Y':
showMeau()
print("您的選擇是:", end=' ')
choice = int(input())
if choice == 1:
questionOne()
isgo = input('\nY回傳選單/N退出系統')
elif choice == 2:
questionTwo(maxminJudge(maxl+minl))
isgo = input('\nY回傳選單/N退出系統')
elif choice == 3:
showMax(maxl)
isgo = input('\nY回傳選單/N退出系統')
elif choice == 4:
showMin(minl)
isgo = input('\nY回傳選單/N退出系統')
else:
isgo = 'N'
if __name__ == '__main__':
main()
三丶運行結果





——山重水復疑無路,柳暗花明又一村——
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/235493.html
標籤:python
