【飛漿百度領航團零基礎Python】學習筆記
阿新 • • 發佈:2021-02-10
飛槳百度領航團大作業
飛槳領航團是飛槳開發者的興趣社群,為開發者們提供豐富的本地技術沙龍、Meetup、及線上交流平臺,面向所有對人工智慧及深度學習領域感興趣的開發者開放。在各個城市/高校領航團團長及成員的熱情支援下,飛槳領航團已建立132個社群,覆蓋28個省級行政區,108個高校,並且在持續增長中。歡迎開發者們加入領航團,結識更多本地技術同好,共建開源社群,共享開源成果與快樂。
定義Student類,包括name、dob、age、gender和score屬性,包括top3方法用來返回學生的最大的3個成績(可重複)、sanitize方法用來將負的分數變為正的分數,負的分數可能是輸入錯誤。宣告stu_list物件組數用於儲存所有的學生物件。最後輸出所有的學生資訊包括姓名、生日、年齡、性別、最高的3個分數。
# 請在此處完成程式碼
def opentext(txt):
with open(txt) as f:
line = f.readline()
# print(line.strip().split(','))
return line.strip().split(',')
class Student():
def __init__(self, name, dob, age, gender, score):
self.name = name
self.dob = dob
self. age = age
self.gender = gender
self.score = score
def name(self):
return self.name
def dob(self):
return self.dob
def age(self):
return self.age
def gender(self):
return self.gender
def top3(self):
newlist = []
for t in self.score:
t = int(t)
if t < 0 :
t = -t
newlist.append(t)
return sorted(newlist)[::-1][:3]
def printf(textname):
txtlist = opentext(textname)
name = txtlist.pop(0)
dob = txtlist.pop(0)
age = txtlist.pop(0)
gender = txtlist.pop(0)
student = Student(name, dob, age, gender, txtlist)
# print(student.name)a
print(f'姓名:{student.name} 生日:{student.dob} 年齡:{student.age} 性別:{student.gender} 分數:{student.top3()}')
printf('work/stu1.txt')
printf('work/stu2.txt')
printf('work/stu3.txt')
printf('work/stu4.txt')
stu5.txt 特長同學,2020-10-5,20,‘男’,180,87,98,77,76,92,58,-76,84,69,-47
stu6.txt 特長同學,2020-10-6,20,‘女’,230,76,48,82,88,92,58,-91,84,69,-68
以上兩個txt文件在work路徑下可以找到。
定義Spostudent、Artstudent為Student的子類,在子類的屬性裡面新增了spe為特長分數。Spostudent包括的top3方法返回的是最低的3個得分(可重複),Artstudent包括top3方法返回的是最高的3個得分(可重複),最後使用多型的方式輸出2個特長同學的姓名、生日、年齡、性別、分數、特長分。
# 請在此處完成程式碼
class Spostudent(Student):
def __init__(self, name, dob, age, gender, score, spe):
Student.__init__(self, name, dob, age, gender, score)
self.spe = spe
def spe(self):
return self.spe
class Artstudent(Student):
def __init__(self, name, dob, age, gender, score):
Student.__init__(self, name, dob, age, gender, score)
def top3(self):
newlist = []
for t in self.score:
t = int(t)
if t < 0 :
t = -t
newlist.append(t)
return sorted(newlist)[0:3]
def printf(text,a):
txtlist = opentext(text)
name = txtlist.pop(0)
dob = txtlist.pop(0)
age = txtlist.pop(0)
gender = txtlist.pop(0)
spe = txtlist.pop(0)
spostudent = Spostudent(name, dob, age, gender, txtlist, spe)
artstudent = Artstudent(name, dob, age, gender, txtlist)
if a == 0:
a = spostudent.top3()
else:
a = artstudent.top3()
print(f'姓名:{spostudent.name} 生日:{spostudent.dob} 年齡:{spostudent.age} 性別:{spostudent.gender} 分數:{a} 特長分:{spostudent.spe}')
printf('work/stu5.txt', 1)
printf('work/stu5.txt', 1)
printf('work/stu6.txt', 0)
課程心得
六天過的很快,意猶未盡,還沒有好好啊體會就結束了,收穫很多也會繼續關注.
平臺的使用就像是工具書
會基礎的使用以後就可以了