當前位置:股票大全官網 - 私募基金 - 用python3怎麽解決這個問題?

用python3怎麽解決這個問題?

#?Python3.6

#?文件地址

記錄_目錄?=?" record.txt "

數據?=?[]

#?第壹個問題

用什麽?打開(記錄目錄,?“r”)?作為?女:

臺詞?=?f.readlines()

為了什麽?線?在?線條:

如果?line.startswith("# "):

繼續

嘗試:

姓名,?年齡,?得分?=?line.split(",")

data.append([name,年齡,?分數])

除了:

Peint("記錄文本格式錯誤!")

#?第二個問題

nm_list?=?[]

為了什麽?d?在?數據:

如果?int(d[2])?& lt?60:

nm_list.append(d[0])

打印(" 60分以下的人:"?nm_list)

#?另壹個寫第二個問題的有效方法

#?打印(" 60分以下的人:"?[d[0]?為了什麽?d?在?數據?如果?int(d[2])?& lt?60])

#?第三個問題

sum_score?=?0

為了什麽?d?在?數據:

sum_score?+=?int(d[2])

打印("總分:",?總和_分數)

#?另壹種寫第三個問題的有效方法

#?打印("總分:",?sum(int(d[2])?為了什麽?d?在?數據))

#?第四個問題

src_name?=?[d[0]?為了什麽?d?在?數據]

Print("原始數據名稱:{0}"。格式(資源中心名稱))

為了什麽?我,?n_?在?枚舉(src_name):

#?Istitle()確定首字母是否大寫。

如果?不是嗎?n_。istitle():

#?大寫()將字符串的第壹個字母大寫。

n_?=?n_。大寫()

src_name[i]?=?n_

Print("修改後的名稱:",?Src_name)關於高效寫作相當於列表的條件過濾。