6.1 Python函数和文件上机实训1. 实训目的(1)掌握Python函数的定义与调用;(2)掌握Python 函数参数传递、返回值、变量作用域;(3)掌握Python函数的特殊形式;(4)掌握Python文件的基本操作。2. 实训步骤(详述每一个题目的关键语法及其实现)2.1 实训任务1-1编写函数f1,接收一个字符串,分别统计大写字母、小写字母、数字、其他字符的个数,并以元组的形式返回结果。代码实现:运行效果图:2.2 实训任务1-2编写函数f2,可以接收任意多个整数,并输出其中的最大值和所有整数之和。代码实现:运行效果图:2.3 实训任务1-3以字典为基础建立一个通讯录,编写函数f3_add,向字典中添加通讯人信息(姓名、电话、email、工作单位等);编写函数f3_delete,传入通讯人姓名,从字典中删除通讯人信息;编写函数f3_search,传入通讯人姓名,从字典中查询某个人的信息。(提示:字典元素格式:{name:[phone,email,place]})代码实现:运行效果图:2.4 实训任务1-4编写函数f4,输入梯形的上底,下底和高,设计函数,输出梯形面积。(提示:梯形面积 = (上底+下底)* 高/2)代码实现:运行效果图:2.5 实训任务1-5编写函数f5,输入年份和月份,返回对应月份有多少天。(提示:注意闰年的判断,闰年的第2月是29天)代码实现:运行效果图:2.6 实训任务1-6定义递归函数f6,,求1+2+3+…+100的和,并输出。代码实现:运行效果图:2.7 实训任务1-7给定一个文件test1.txt;任意输入一个字符,比如“a”,统计输出该字符在文件test1.txt中的个数。(提示:test1.txt的内容自定义)代码实现:运行效果图:3. 实训收获与总结
4. Listen to a dialogue and decode the message by finding out the correct choicesin the brackets according to what you have heard.Mike and Claire are discussing their plans for 1 (today, tomorrow, the day after tomorrow) . Mike suggests going to the 2 (ball room, ball game, ball match) , but Claire doesn’t want to. Then Mike invites Claire to go 3 (skating, skiing, skidding) . Claire loves this idea as she hasn’t done it 4( for a short time, for a few years, for a long time) . But Claire seems to remember that it’s supposed to be 5 (very wet, quite cold, very warm tomorrow). In that case, it won’t be a good idea to go skiing. So, they 6( ) to wait and see what the weather will be like tomorrow.