飞桨百度领航团零基础Python学习心得
发布于2021-02 浏览:1336 回复:0
0
收藏

【百度飞桨领航团零基础Python速成营】 全程采用直播+答疑+实践作业的学习模式,6天时间里每日直播打卡学习、完全覆盖Python知识点、配合项目实战、全程社群答疑,带你吃透Python语言、学透深度学习前置知识点,百度为我们准备的零基础课程对我们这样想在假期提升自己能力的学生来说是非常友好的,首先老师们具有非常丰富的经验并且对我们非常的有耐心,而且这样的课程竟然免费!!!对于我这样想提升自己的白嫖党来说是相当友好的。

这6节课让我们了解并掌握了python基础,当然python作为当下非常流行的语言之一,想能够熟练掌握并将其作为自己的工具还是需要我们在未来的日子里多加练习的。

我曾在去年寒假的时候了解过python,但是对于python基础大多是一知半解,练习过简单的爬虫,练习过写宇宙飞船这种简单的游戏的代码,说是练习其实也就是一味的模仿罢了。因为对基础没有系统的深入的展开学习再加上在学校课程太紧没有太多时间来看它,所以一年让我把之前看过的一点知识都忘掉了,不过经过这次对python基础的学习,通过老师的讲解,作业的练习,大家的讨论,以及自己的琢磨,这六天让我再一次感受到了python的魅力以及自己学习下去的自信。

再来说说我们为什么要学python,作为计算机专业的我来说,它很有可能以后成为我吃饭的工具,当然如果不是计算机专业,python的掌握也可以让你在工作中节省很多时间,python在数据处理等方面是非常方便的。

python的特点
简洁性 实现同样的功能,python代码的行数往往是java的1/5。

易读性 代码像纯英语一样易于理解。

可扩展性 开源,任何人都可以做出自己的贡献。

这样的特点就使得一些没有编程基础的小白们也可以很快的去掌握它。

另外python的应用领域非常的广,这次我们的基础学习就是为了之后的深度学习打下了基础。

再来看看学习的作业也算是6天学习的成果:

day1:

零基础Python速成营 作业一:Python编程基础
按要求补全下列代码
1. 输入两个整数,并打印出它们的和
In [9]
a = input('请输入第一个整数: ')
b = input('请输入第二个整数:\r\n ')

# 分别把 a、b 转换成整数
a= int(a)
b= int(b)


# 计算 a、b 的和,赋值给变量c
c=a+b

# 打印c
print(c)
请输入第一个整数:
请输入第二个整数:
3

2. 输入两个整数,如果两个整数之和小于100,则输出 '小于100',否则输出 '不小于100'
In [11]
a = input('请输入第一个整数: ')
b = input('请输入第二个整数:\r\n ')

# 分别把 a、b 转换成整数
a=int(a)
b=int(b)

# 计算 a、b 的和,赋值给变量c
c=a+b

# 判断c是否小于100,按要求输出
if c<100:
print('小于100')
else:
print('不小于100')
请输入第一个整数:
请输入第二个整数:
小于100

3. 输入两组姓名和年龄,然后存入一个字典,并输出
In [14]
name1 = input('请输入第一个姓名: ')
age1= input('请输入第一个年龄: ')
name2 = input('请输入第二个姓名: ')
age2 = input('请输入第二个年龄:\r\n ')

# 分别把age1和age2转成整数
age1=int(age1)
age2=int(age2)

# 构造字典dict_name
dict_name = {name1:age1,name2:age2}

# 打印字典
print(dict_name)
请输入第一个姓名:
请输入第一个年龄:
请输入第二个姓名:
请输入第二个年龄:
{'1': 19, '2': 20}

4. 依次输入10组整数,然后求和,并输出
In [11]
sum_num = 0
for i in range(10):
# 用input输入数字并转化为整数
a=input('输入一个整数')
a1=int(a)
print(a1)
# sum_num 对输入的数字进行累加
sum_num +=a1

print(sum_num)

day2:

按要求完成下列代码
1. 选取列表的第2到第5项,并打印(从0开始计数,即取出c d e f)
In [3]
words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']

# 选取第2-5项,并打印
print(words[2:6])

['c', 'd', 'e', 'f']

2. 使用列表生成式的方法,根据 list1 生成 list2
list1 = [1, 2, 3, 4, 5, 6, 7, 8]

# 根据list1生成list2
list2 = [100, 200, 300, 400, 500, 600, 700, 800]

In [5]
list1 = [1, 2, 3, 4, 5, 6, 7, 8]

# 列表推导式生成list2
list2 = [x*100 for x in list1]

print(list2)
[100, 200, 300, 400, 500, 600, 700, 800]

3. 把下列字符串按下划线('_')划分成若干个片段
string1 = 'this_is_a_sample'

# 生成按'_'划分的字符串列表,即下列内容
['this', 'is', 'a', 'sample']

In [9]
string1 = 'this_is_a_sample'

# 按'_'划分string1
string1.split('_')

['this', 'is', 'a', 'sample']

day3:

Lesson 3 大作业
作业内容
统计英语6级试题中所有单词的词频,并返回一个如下样式的字典

{'and':100,'abandon':5}

英语6级试题的文件路径./artical.txt

Tip: 读取文件的方法

def get_artical(artical_path):
with open(artical_path) as fr:
data = fr.read()
return data

get_artical('./artical.txt')

处理要求

(a) '\n'是换行符 需要删除
(b) 标点符号需要处理
['.', ',', '!', '?', ';', '\'', '\"', '/', '-', '(', ')']

(c) 阿拉伯数字需要处理
['1','2','3','4','5','6','7','8','9','0']

(d) 注意大小写 一些单词由于在句首,首字母大写了。需要把所有的单词转成小写
'String'.lower()

(e) 高分项
通过自己查找资料学习正则表达式,并在代码中使用(re模块)

可参考资料:https://docs.python.org/3.7/library/re.html
In [80]
# 请根据处理要求下面区域完成代码的编写。
def get_artical(artical_path):
with open(artical_path) as fr:
data = fr.read()
return data

# get_artical()为自定义函数,可用于读取指定位置的试题内容。
# get_artical('./artical.txt')
a=get_artical('./artical.txt')
g=['.', ',', '!', '?', ';', '\'', '\"', '/', '-', '(', ')','\n','1','2','3','4','5','6','7','8','9','0',' ']
#b=a.replace('\n',' ')
#c=b.split(' ')
for i in g:
a=a.replace(i,' ') #去掉标点以及换行
a=a.replace(' ',' ')#去掉标点后,有的地方会存在两个空格,将两个空格的地方替换成一个
#print(a)
b=a.split(' ')
#print(b)
s=[s.lower() for s in b]#大写变小写
#print(s)
count={}
for n in s:
if n not in count:
count[n]=1
else:
count[n]+=1
print(count)

 

 

 

 

 

{'passage': 11, 'one': 12, 'questions': 4, 'to': 95, 'are': 25, 'based': 5, 'on': 25, 'the': 169, 'following': 4, 'last': 3, 'year': 1, 'a': 87, 'child': 3, 'was': 10, 'born': 2, 'at': 7, 'hospital': 1, 'in': 61, 'uk': 1, 'with': 19, 'her': 5, 'heart': 1, 'outside': 2, 'body': 3, 'few': 3, 'babies': 1, 'survive': 1, 'this': 9, 'rare': 1, 'condition': 1, 'and': 74, 'those': 6, 'who': 3, 'do': 11, 'must': 1, 'endure': 1, 'numerous': 1, 'operations': 3, 'likely': 2, 'have': 12, 'complex': 1, 'needs': 1, 'when': 7, 'mother': 1, 'interviewed': 1, 'three': 1, 'weeks': 1, 'after': 1, 'daughter': 1, 's': 23, 'birth': 1, 'she': 4, 'asked': 2, 'if': 6, 'prepared': 1, 'for': 22, 'what': 25, 'might': 1, 'be': 18, 'daunting': 1, 'task': 1, 'caring': 1, 'answered': 1, 'without': 2, 'hesitation': 1, 'that': 25, 'as': 18, 'far': 1, 'concerned': 1, 'would': 3, 'privilege': 2, 'rarely': 1, 'has': 5, 'there': 6, 'been': 4, 'better': 4, 'example': 2, 'of': 82, 'power': 1, 'attitude': 6, 'our': 9, 'most': 4, 'powerful': 2, 'psychological': 3, 'tools': 1, 'attitudes': 8, 'allow': 1, 'us': 2, 'turn': 3, 'mistakes': 1, 'into': 3, 'opportunities': 3, 'loss': 1, 'chance': 3, 'new': 10, 'beginnings': 1, 'an': 9, 'is': 34, 'settled': 1, 'way': 6, 'thinking': 1, 'feeling': 1, 'or': 9, 'behaving': 3, 'towards': 2, 'particular': 1, 'objects': 1, 'people': 5, 'events': 3, 'ideologies': 2, 'we': 13, 'use': 1, 'filter': 1, 'interpret': 1, 'react': 1, 'world': 6, 'around': 9, 'you': 16, 'weren': 1, 't': 11, 'rather': 2, 'they': 30, 'all': 6, 'learned': 1, 'happens': 2, 'number': 1, 'ways': 3, 'influences': 1, 'occur': 1, 'during': 2, 'early': 1, 'childhood': 1, 'include': 1, 'both': 2, 'happened': 1, 'directly': 1, 'did': 2, 'said': 3, 'your': 8, 'presence': 1, 'acquire': 1, 'distinctive': 1, 'identity': 1, 'further': 3, 'refined': 1, 'by': 6, 'behavior': 6, 'whom': 1, 'identify': 1, 'family': 2, 'gender': 2, 'culture': 1, 'admire': 1, 'even': 4, 'though': 3, 'may': 10, 'not': 10, 'know': 1, 'them': 11, 'personally': 1, 'friendships': 1, 'other': 3, 'important': 2, 'relationships': 1, 'become': 4, 'increasingly': 3, 'particularly': 1, 'adolescence': 1, 'about': 13, 'same': 2, 'time': 5, 'throughout': 2, 'adulthood': 1, 'information': 1, 'receive': 1, 'especially': 1, 'ideas': 1, 'repeated': 1, 'association': 1, 'goals': 2, 'achievements': 1, 'find': 8, 'attractive': 1, 'also': 2, 'refines': 1, 'many': 10, 'assume': 1, 'internally': 2, 'consistent': 3, 'think': 5, 'feel': 4, 'someone': 1, 'something': 2, 'predicts': 1, 'however': 2, 'studies': 2, 'found': 4, 'feelings': 2, 'thoughts': 2, 'don': 7, 'necessarily': 1, 'predict': 1, 'general': 1, 'will': 12, 'only': 7, 'easy': 2, 'hold': 1, 'similar': 1, 'beliefs': 2, 'why': 3, 'say': 4, 'believe': 4, 'benefits': 1, 'recycling': 1, 'exercise': 1, 'but': 9, 'behave': 2, 'line': 3, 'their': 28, 'views': 1, 'because': 3, 'it': 19, 'takes': 1, 'awareness': 2, 'effort': 1, 'courage': 1, 'go': 1, 'beyond': 1, 'merely': 1, 'stating': 1, 'good': 3, 'idea': 2, 'effective': 1, 'change': 11, 'start': 2, 'already': 2, 'd': 21, 'prefer': 1, 'take': 2, 'some': 6, 'reflect': 1, 'anything': 1, 'consider': 2, 'burden': 1, 'than': 3, 'so': 1, 'right': 1, 'now': 1, 'latter': 1, 'case': 2, 'learn': 4, 'from': 12, 'shapes': 1, 'b': 20, 'improves': 1, 'wellbeing': 1, 'c': 20, 'determines': 1, 'how': 5, 'respond': 1, 'immediate': 4, 'environment': 4, 'changes': 3, 'interact': 1, 'another': 2, 'can': 13, 'contribute': 2, 'refinement': 1, 'according': 5, 'idols': 1, 'behaviors': 1, 'educational': 2, 'level': 3, 'contact': 1, 'opposite': 1, 'interaction': 1, 'different': 2, 'cultures': 1, 'suggest': 2, 'person': 3, 'going': 2, 'mentality': 1, 'expression': 1, 'interpersonal': 1, 'relations': 1, 'no': 5, 'matter': 1, 'come': 2, 'afford': 2, 'hypocritical': 1, 'lack': 1, 'willpower': 1, 'proposed': 3, 'strategy': 1, 'changing': 2, 'things': 1, 'require': 2, 'attention': 1, 'starting': 1, 'act': 1, 'embodies': 1, 'aspirations': 1, 'adjusting': 1, 'gradually': 1, 'over': 3, 'period': 1, 'considering': 1, 'reducing': 1, 'burdens': 1, 'two': 3, 'industrial': 3, 'fishing': 20, 'krill': 14, 'unspoilt': 1, 'waters': 5, 'antarctica': 4, 'threatening': 2, 'future': 4, 'great': 4, 'wildernesses': 1, 'report': 5, 'study': 7, 'greenpeace': 6, 'analysed': 1, 'movements': 1, 'vessels': 1, 'region': 5, 'were': 2, 'operating': 1, 'vicinity': 1, 'penguin': 7, 'colonies': 6, 'whale': 1, 'feeding': 2, 'grounds': 10, 'highlights': 1, 'incidents': 1, 'boats': 1, 'being': 6, 'involved': 1, 'groundings': 1, 'oil': 1, 'spills': 1, 'accidents': 1, 'which': 5, 'posed': 2, 'serious': 1, 'threat': 2, 'antarctic': 33, 'ecosystem': 3, 'published': 1, 'tuesday': 1, 'comes': 1, 'amid': 2, 'growing': 2, 'concern': 3, 'impact': 5, 'climate': 7, 'global': 7, 'campaign': 5, 'launched': 3, 'create': 1, 'network': 1, 'ocean': 10, 'sanctuaries': 3, 'protect': 4, 'seas': 4, 'calling': 1, 'halt': 1, 'areas': 5, 'considered': 1, 'sanctuary': 5, 'status': 1, 'frida': 1, 'bengtsson': 1, 'said:': 3, 'industry': 2, 'wants': 1, 'show': 1, 'responsible': 1, 'player': 1, 'then': 1, 'should': 6, 'voluntarily': 1, 'getting': 1, 'out': 7, 'any': 3, 'area': 4, 'instead': 1, 'backing': 1, 'protection': 2, 'these': 4, 'huge': 3, 'tracts': 1, 'tract': 1, 'protecting': 1, 'wildlife': 2, 'banning': 1, 'just': 3, 'created': 1, 'ross': 1, 'sea': 7, 'reserve': 1, 'vast': 1, 'weddell': 2, 'third': 1, 'under': 1, 'consideration': 1, 'west': 1, 'peninsula': 2, 'key': 4, 'commission': 1, 'conservation': 6, 'marine': 10, 'living': 1, 'resources': 1, 'ccamlr': 5, 'manages': 1, 'decide': 2, 'proposal': 1, 'conference': 1, 'australia': 1, 'october': 1, 'although': 3, 'decision': 1, 'expected': 2, 'until': 1, 'later': 2, 'keith': 1, 'reid': 1, 'science': 2, 'manager': 2, 'organisation': 1, 'sought': 1, 'balance': 1, 'between': 3, 'sustainable': 2, 'southern': 6, 'he': 2, 'more': 3, 'taking': 1, 'place': 1, 'nearer': 1, 'often': 1, 'happening': 1, 'season': 2, 'empty': 1, 'creation': 1, 'system': 1, 'protected': 2, 'part': 2, 'ongoing': 1, 'scientific': 2, 'policy': 2, 'discussions': 2, 'added': 1, 'long': 2, 'term': 1, 'operation': 1, 'depends': 1, 'healthy': 1, 'thriving': 1, 'always': 1, 'had': 1, 'open': 2, 'dialogue': 2, 'environmental': 1, 'non': 1, 'governmental': 1, 'organisations': 1, 'strongly': 1, 'intend': 1, 'continue': 1, 'including': 1, 'talks': 1, 'discuss': 1, 'improvements': 1, 'latest': 1, 'data': 2, 'ones': 1, 'establishment': 1, 'hope': 1, 'positively': 1, 'knowledge': 1, 'experience': 2, 'does': 8, 'caused': 1, 'penguins': 18, 'whales': 7, 'migrate': 3, 'depriving': 1, 'habitats': 3, 'carried': 1, 'too': 2, 'close': 2, 'unprecedented': 1, 'purpose': 1, 'reduce': 1, 'establish': 1, 'regulate': 1, 'publicise': 1, 'recommendation': 1, 'opting': 1, 'operate': 1, 'away': 1, 'suggested': 1, 'volunteering': 1, 'endangered': 1, 'species': 8, 'refraining': 1, 'breeding': 11, 'showing': 1, 'its': 5, 'sense': 1, 'responsibility': 1, 'leading': 1, 'aim': 1, 'raise': 1, 'public': 1, 'vulnerability': 1, 'ban': 1, 'commercial': 1, 'keep': 2, 'interference': 1, 'sustain': 1, 'damaging': 1, 'define': 1, 'role': 1, 'coordinator': 1, 'authority': 1, 'big': 1, 'analysis': 1, 'provider': 1, 'needed': 1, 'expertise': 1, 'initiator': 1, 'schools': 9, 'microcosm': 1, 'society': 4, 'mediate': 1, 'best': 2, 'seek': 1, 'alleviate': 1, 'external': 1, 'pressures': 3, 'pupils': 4, 'while': 1, 'equipping': 1, 'understand': 1, 'handle': 1, 'once': 1, 'sheltering': 1, 'broadening': 1, 'horizons': 2, 'ambitious': 2, 'circumstances': 1, 'divided': 2, 'unequal': 2, 'ideals': 1, 'clash': 1, 'outright': 1, 'trips': 7, 'adults': 1, 'adventure': 1, 'lifetime': 1, 'treks': 1, 'bomeo': 1, 'sports': 1, 'tour': 1, 'barbados': 1, 'appear': 1, 'almost': 1, 'routine': 1, 'state': 1, 'parents': 5, 'thousands': 1, 'pounds': 3, 'cannot': 3, 'profit': 1, 'companies': 1, 'arrange': 1, 'meanwhile': 1, 'arrive': 1, 'school': 6, 'hungry': 2, 'families': 2, 'breakfast': 1, 'poverty': 2, 'action': 1, 'group': 1, 'says': 2, 'nine': 1, 'every': 1, 'classroom': 1, 'fall': 1, 'below': 1, 'discrepancy': 1, 'startlingly': 1, 'apparent': 1, 'introducing': 1, 'fundraising': 2, 'requirement': 1, 'students': 15, 'help': 6, 'off': 1, 'children': 6, 'tap': 1, 'up': 2, 'richer': 1, 'aunts': 1, 'neighbours': 2, 'probing': 1, 'rock': 1, 'pools': 1, 'local': 1, 'beach': 1, 'practising': 1, 'french': 1, 'language': 1, 'exchange': 1, 'fire': 1, 'passions': 1, 'boost': 1, 'skills': 1, 'eyes': 1, 'life': 3, 'possibilities': 1, 'outings': 1, 'bright': 1, 'disadvantaged': 4, 'get': 1, 'scores': 1, 'tests': 1, 'globalised': 1, 'age': 1, 'international': 1, 'travel': 3, 'manage': 1, 'cost': 2, 'trip': 3, 'abroad': 1, 'easily': 1, 'holiday': 1, 'face': 3, 'immense': 1, 'mounting': 1, 'financial': 1, 'shown': 1, 'remarkable': 1, 'determination': 1, 'ingenuity': 3, 'ensuring': 1, 'able': 2, 'truly': 1, 'applauded': 1, 'methods': 1, 'such': 4, 'whole': 1, 'proceeds': 1, 'pooled': 1, 'extend': 1, 'fuel': 2, 'community': 4, 'spirit': 2, '': 3, 'justified': 1, 'average': 1, 'income': 2, 'initiatives': 1, 'doors': 1, 'pull': 1, 'expensive': 1, 'field': 3, 'see': 4, 'little': 1, 'party': 1, 'celebration': 1, 'well': 2, 'guilt': 1, 'left': 1, 'behind': 1, 'department': 1, 'education': 1, 'guidance': 1, 'charge': 1, 'board': 1, 'lodging': 1, 'syllabus': 1, 'receiving': 1, 'government': 1, 'aid': 1, 'exempt': 1, 'costs': 1, 'seem': 1, 'ignore': 1, 'advice': 1, 'cover': 3, 'kind': 1, 'glamorous': 1, 'exotic': 1, 'becoming': 1, 'common': 1, 'bring': 1, 'together': 2, 'communities': 1, 'single': 1, 'handed': 1, 'least': 1, 'expect': 1, 'foster': 1, 'divisions': 1, 'exclude': 1, 'author': 5, 'prepare': 1, 'challenge': 1, 'social': 1, 'enable': 2, 'motivate': 1, 'develop': 1, 'physical': 1, 'intellectual': 1, 'abilities': 1, 'encourage': 1, 'achieve': 1, 'backgrounds': 1, 'mix': 1, 'each': 1, 'widen': 1, 'gap': 1, 'privileged': 1, 'give': 1, 'benefit': 2, 'rich': 2, 'relatives': 1, 'build': 1, 'aiming': 1, 'improve': 1, 'services': 1, 'activities': 3, 'mutual': 1, 'understanding': 2, 'involving': 1, 'campus': 1, 'low': 1, 'regarding': 1, 'want': 5, 'participate': 2, 'much': 2, 'kids': 2, 'hard': 1, 'miss': 1, 'broaden': 1, 'despite': 1, 'adventures': 1, 'run': 1, 'risks': 1, 'expectation': 1, 'bringing': 1, 'resolving': 1, 'existing': 1, 'discrepancies': 1, 'avoiding': 1, 'creating': 1, 'gaps': 1, 'among': 1, 'giving': 1, 'poor': 1, 'preferential': 1, 'treatment': 1, 'rising': 2, 'temperatures': 2, 'overfishing': 2, 'pristine': 3, 'could': 6, 'king': 15, 'populations': 1, 'pushed': 2, 'brink': 1, 'extinction': 2, 'end': 1, 'century': 1, 'states': 1, 'warming': 4, 'transforms': 1, 'wilderness': 2, 'percent': 2, 'either': 1, 'disappear': 3, 'forced': 2, 'co': 1, 'celine': 1, 'le': 3, 'bohec': 3, 'university': 1, 'strasbourg': 1, 'france': 1, 'warned:': 1, 're': 1, 'actions': 1, 'aimed': 1, 'halting': 1, 'controlling': 1, 'pace': 1, 'current': 2, 'human': 3, 'induced': 1, 'stays': 1, 'soon': 1, 'findings': 2, 'earlier': 1, 'month': 1, 'separate': 2, 'combination': 1, 'population': 2, 'potentially': 2, 'disastrous': 1, 'seals': 1, 'today': 1, 'starkest': 1, 'yet': 1, 'devastating': 1, 'exploitation': 1, 'delicate': 1, 'ecosystems': 4, 'unless': 1, 'greenhouse': 1, 'gas': 1, 'emissions': 1, 'drop': 1, 'million': 1, 'pairs': 1, 'relocate': 2, 'second': 2, 'largest': 2, 'type': 1, 'breed': 1, 'specific': 1, 'isolated': 2, 'islands': 4, 'where': 1, 'ice': 2, 'access': 1, 'warms': 1, 'water': 3, 'called': 1, 'polar': 2, 'front': 2, 'upward': 1, 'movement': 1, 'nutrient': 1, 'supports': 1, 'abundance': 1, 'south': 1, 'means': 1, 'feed': 2, 'fish': 1, 'kill': 2, 'leaving': 1, 'chicks': 1, 'longer': 2, 'distance': 1, 'fool': 1, 'prows': 1, 'entire': 2, 'wiped': 1, 'plight': 1, 'serve': 2, 'like': 2, 'seabirds': 1, 'mammals': 1, 'occupy': 1, 'higher': 2, 'levels': 2, 'food': 4, 'chain': 1, 'call': 1, 'bio': 1, 'indicators': 2, 'sensitive': 1, 'predicting': 1, 'impacts': 1, 'sub': 1, 'closer': 1, 'retreating': 1, 'source': 1, 'suitable': 2, 'scarce': 1, 'handful': 1, 'sustaining': 1, 'large': 1, 'happen': 1, 'verge': 1, 'dying': 1, 'rise': 2, 'melting': 1, 'destroy': 1, 'forever': 1, 'shrinking': 1, 'force': 1, 'accelerated': 1, 'recent': 1, 'years': 1, 'fatal': 1, 'certain': 1, 'worsened': 1, 'pollution': 1, 'birds': 1, 'extinct': 1, 'primarily': 1, 'kinds': 1, 'majority': 1, 'baby': 1, 'live': 1, 'invade': 1, 'distances': 1, 'reluctant': 1, 'leave': 1, 'propagation': 1, 'ultimate': 1, 'retreat': 1, 'luge': 1}

day4:

第1题
'james,2006-11-11,2-34,3:21,2.34,2.45,3.01,2:01,2:01,3:10,2-22'

存储以上的数据,如何定义运动员类,补全代码(4分)
In [18]
class Athlete:

def __init__(self,a_name,a_dob=None,a_times=[]):


#代码1
self.name = a_name
self.dob = a_dob
self.times = a_times
def top3(self):
#代码2
return sorted(set([self.sanitize(t) for t in self.times]))
def sanitize(self,time_string):
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return (time_string)
(mins,secs) = time_string.split(splitter)
return (mins+'.'+secs)
第2题
数据所在文件的路径为'work/james_new.txt',使用运动员对象,补全代码(4分)
In [19]
def get_coach_data(filename):
with open(filename) as f:
line = f.readline()
return line.strip().split(',')

#从文件中读取数据
#代码1
james_new = get_coach_data('work/james_new.txt')
james_name = james_new.pop(0)
james_dob = james_new.pop(0)
james_times = james_new
#代码2

#创建Athlete对象
#代码3
james = Athlete(james_name,james_dob,james_times)

#代码4
print('姓名:%s,生日:%s,最快的3次成绩:%s' %(james.name,james.dob,james.top3()))
姓名:james,生日:2006-11-11,最快的3次成绩:['2.01', '2.22', '2.34', '2.45', '3.01', '3.10', '3.21']

第3题
类属性,类方法,补全代码(4分)
In [20]
class Athlete:

#运动员集训了,要买东西的同学要把地址改一下
#代码1
address = '中国足球协会训练基地xx街xx号'

def __init__(self,a_name,a_dob=None,a_times=[]):
self.name = a_name
self.dob = a_dob
self.times = a_times

def top3(self):
return sorted(set([self.sanitize(t) for t in self.times]))[0:3]

def sanitize(self,time_string):
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return (time_string)
(mins,secs) = time_string.split(splitter)
return (mins+'.'+secs)
#代码2
@classmethod
def changeAddress(self):
self.address = '中国田径训练基地xx街xx号'
#代码3
Athlete.changeAddress()
print(julie.address)
print(james.address)
print(Athlete.address)

 

第4题
将第3题中的实例变量name改为私有的属性,将sanitize改为私有方法,补全代码(4分)
In [48]
class Athlete:
def __init__(self,a_name,a_dob=None,a_times=[]):
#代码1
self.__name = a_name
self.dob = a_dob
self.times = a_times

def sayName(self):
#代码2
print(self.__name)

def top3(self):
#代码3
return sorted(set([self.__sanitize(t) for t in self.times]))[0:3]

#代码4
def __sanitize(self,time_string):
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return (time_string)
(mins,secs) = time_string.split(splitter)
return (mins+'.'+secs)
第5题
数据内容james,2006-11-11,2-34,3:21,2.34,2.45,3.01,2:01,2:01,3:10,2-22,以分钟.秒的形式打印'2-34'后面的所有时间。

输出的结果为'2.34', '3.21', '2.34', '2.45', '3.01', '2.01', '2.01', '3.10', '2.22',补全代码。(4分)
In [52]
data = 'james,2006-11-11,2-34,3:21,2.34,2.45,3.01,2:01,2:01,3:10,2-22'

def sanitize(time_string):

#代码1
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return (time_string)
(mins,secs) = time_string.split(splitter)
return (mins+'.'+secs)
#代码2
james=data.split(',')
name =james.pop(0)
dob = james.pop(0)
times=[sanitize(t) for t in james]
#代码3
print(times)
['2.34', '3.21', '2.34', '2.45', '3.01', '2.01', '2.01', '3.10', '2.22']

day5:

第1题
In [7]
#1题 定义Rugby为Athlete的子类,并增加子类自己的属性squat。(5分)

class Athlete:
def __init__(self,a_name,a_dob=None,a_times=[]):
self.name = a_name
self.dob = a_dob
self.times = a_times
def top3(self):
return sorted(set([self.sanitize(t) for t in self.times]))[0:3]
def sanitize(self,time_string):
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return (time_string)
(mins,secs) = time_string.split(splitter)
return (mins+'.'+secs)

 

#代码1,定义Rugby类继承Athlete
class Rugby (Athlete):

def __init__(self,a_name,a_dob,a_squat,a_times):

#代码2,调用父类的构造方法,传递的参数为a_dob、a_times
Athlete.__init__(self,a_name,a_dob,a_times)
#代码3,将a_squat赋值给类属性squat
self.squat=a_squat
第2题
In [8]
#2题 定义OtherAthlete类为Athlete类的子类,重写top3方法(允许重复的时间) (5分)

#代码1,定义OtherAthlete类继承Athlete
clsss OtherAthlete (Athlete):
def __init__(self,a_name,a_bod,a_squat,a_times):
......


#代码2,定义无参数top3函数,对self.times属性应用统一化和排序功能
return sorted([self.sanitize(t) for t in self.times ])[0:3]
File "", line 4 clsss OtherAthlete (Athlete): ^ IndentationError: unexpected indent
第3题
In [ ]
#3题 定义print_rugby函数,以多态的方式调用子类属性和方法 (5分)

loren = get_coach_data('mywork/loren.txt')
mark = get_coach_data('mywork/mark.txt')

loren = Rugby(loren.pop(0),loren.pop(0),loren.pop(0),loren)
mark = OtherAthlete(mark.pop(0),mark.pop(0),mark.pop(0),mark)


def print_rugby(athlete):
print(athlete.name)
#代码1,打印athlete的属性dob、squat和top3方法的返回值
print(athlete.dob)
print(athlete.squat)
print(athlete.top3())


#代码2,调用print_rugby函数,参数为loren
print_rugby(loren)
#代码3,调用print_rugby函数,参数为mark
print_rugby(mark)
第4题
In [ ]
#4题 有两个父类,一个Father,一个Mother,定义Child类共同继承这两个父类,子类调用父类的属性和方法 (5分)

class Father():
def __init__(self):
self.color = 'black'
def talk(self):
print("---爸爸的表达能力---")

class Mother():
def __init__(self):
self.height = 170
def smart(self):
print("---妈妈聪明的头脑---")

#代码1,定义Child类继承Father和Mother
class Child(Father,Mother):
def __init__(self):
#代码2,调用Mother类的的__init__方法
Father.__init__(self)
Mother.__init__(self)
#代码3,创建Child类的对象child,调用无参数的构造方法
child=Child()

#代码4,通过child调用父类的smart方法
child.smart()
#代码5,通过child打印父类的color属性
print(child.color)

day6:

第一题(30分)
数据如下:

stu1.txt 孙同学,2020-5-21,20,'男',77,56,77,76,92,58,-91,84,69,-91
stu2.txt 赵同学,2020-11-3,24,'女',65,68,72,95,-81,71,86,91,57,91
stu3.txt 王同学,2021-8-7,25,'男',87,78,90,-76,88,47,100,65,69,100
stu4.txt 李同学,2021-8-10,29,'男',92,54,85,71,-91,68,77,68,95,95

以上四个txt文档在work路径下可以找到。

定义Student类,包括name、dob、age、gender和score属性,包括top3方法用来返回学生的最大的3个成绩(可重复)、sanitize方法用来将负的分数变为正的分数,负的分数可能是输入错误。声明stu_list对象组数用于存储所有的学生对象。最后输出所有的学生信息包括姓名、生日、年龄、性别、最高的3个分数。

第一题的输出结果如下,供参考:


In [24]
# 请在此处完
def get_coach_data(filename):
with open(filename) as f:
line = f.readline()
return line.strip().split(',')
class Student:
def __init__(self,a_name,a_dob,a_age,a_gender,a_score):
self.name=a_name
self.dob=a_dob
self.age=a_age
self.gender=a_gender
self.sorce=a_score
def top3(self):
return sorted([self.sanitize(s) for s in self.sorce])[-3:]
def sanitize(self,scores_string):
scores_string= scores_string.strip('-')
target = int(scores_string)
return (target)
a =get_coach_data('work/stu1.txt')
a = Student(a.pop(0),a.pop(0),a.pop(0),a.pop(0),a)
b =get_coach_data('work/stu2.txt')
b = Student(b.pop(0),b.pop(0),b.pop(0),b.pop(0),b)
c=get_coach_data('work/stu3.txt')
c = Student(c.pop(0),c.pop(0),c.pop(0),c.pop(0),c)
d=get_coach_data('work/stu4.txt')
d = Student(d.pop(0),d.pop(0),d.pop(0),d.pop(0),d)
stu_list=[a,b,c,d]
for i in stu_list:
print('姓名{},生日:{},年龄:{},性别:{},分数:{}'.format(i.name,i.dob,i.age,i.gender,i.top3()))

姓名孙同学,生日:2020-5-21,年龄:20,性别:'男',分数:[91, 91, 92]
姓名赵同学,生日:2020-11-3,年龄:24,性别:'女',分数:[91, 91, 95]
姓名王同学,生日:2021-8-7,年龄:25,性别:'男',分数:[90, 100, 100]
姓名李同学,生日:2021-8-10,年龄:29,性别:'男',分数:[92, 95, 95]

第二题(30分)
数据格式如下:

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个特长同学的姓名、生日、年龄、性别、分数、特长分。

第二题的输出结果如下,供参考:


In [31]
# 请在此处完成代码
class Spostudent(Student):
def __init__(self,a_name,a_dob,a_age,a_gender,a_spe,a_score):
Student.__init__(self,a_name,a_dob,a_age,a_gender,a_score)
self.spe=a_spe
def top3(self):
return sorted([self.sanitize(s) for s in self.sorce])[0:3]
class Artstudent(Student):
def __init__(self,a_name,a_dob,a_age,a_gender,a_spe,a_score):
Student.__init__(self,a_name,a_dob,a_age,a_gender,a_score)
self.spe=a_spe
def top3(self):
return sorted([self.sanitize(s) for s in self.sorce])[-3:]
stu5 = get_coach_data('work/stu5.txt')
#print(stu5)
stu5 = Spostudent(stu5.pop(0),stu5.pop(0),stu5.pop(0),stu5.pop(0),stu5.pop(0),stu5)
stu6 = get_coach_data('work/stu6.txt')
#print(stu6)
stu6 = Artstudent(stu6.pop(0),stu6.pop(0),stu6.pop(0),stu6.pop(0),stu6.pop(0),stu6)
print('姓名:{},生日:{},年龄:{},性别:{},分数:{},特长分:{}'.format(stu5.name,stu5.dob,stu5.age,stu5.gender,stu5.top3(),stu5.spe))
print('姓名:{},生日:{},年龄:{},性别:{},分数:{},特长分:{}'.format(stu6.name,stu6.dob,stu6.age,stu6.gender,stu6.top3(),stu6.spe))

 


姓名:特长同学,生日:2020-10-5,年龄:20,性别:'男',分数:[56, 58, 69],特长分:180
姓名:特长同学,生日:2020-10-6,年龄:20,性别:'女',分数:[91, 91, 92],特长分:230

这六天的学习确实还挺累人的,因为确实会有一些大佬,好多人会很快的完成作业,所以为了不落后自己学的也很努力,在手机和追剧的诱惑下其实这样的充实自己也很好,最后呢再一次感谢百度飞桨领航团可以提供这样免费的平台让我们学习,提升自己。

课程链接:https://aistudio.baidu.com/aistudio/course/introduce/7073

收藏
点赞
0
个赞
TOP
切换版块