Python第八章实验报告
一.实验对象:《零基础学Python》第八章的3道实例和4道实战
二.实验环境:IDLE Shell 3.9.7
三.实验要求:学习使用标准模块和第三方模块
四.实验过程:
- 实例01 创建计算BMI指数的模块

点击查看代码
def fun_bmi(person,height,weight):
'''功能:根据身高和体重计算BMI指数
person:姓名
height:身高,单位:米
weight:体重,单位:千克
'''
print(person+"的身高:"+str(height)+"米\t体重:"+str(weight)+"千克")
bmi=weight/(height*height)
print(person+"的BMI指数为:"+str(bmi))
#此处省略了显示判断结果的代码
def fun_bmi_upgrade(*person):
'''功能:根据身高和体重计算BMI指数(升级版)
*person:可变参数该参数中需要传递带3个元素的列表,
分别为姓名、身高(单位:米)和体重(单位:千克)
'''
#此处省略了函数主体代码
、
- 实例02 导入两个包括同名函数的模块

点击查看代码
def girth(width,height):
'''功能:计算周长
参数:width(宽度)、height(高)
'''
return(width+height)*2
def area(width,height):
'''功能:计算面积
参数:width(宽度)、height(高)
'''
return width*height
if __name__=='__main__':
print(area(10,20))
、

点击查看代码
import math
PI=math.pi
def girth(r):
'''功能:计算周长
参数:r(半径)
'''
return round(2*PI*r,2)
def area(r):
'''功能:计算面积
参数:r(半径)
'''
return round(PI*r*r,2)
if __name__=='__main__':
print(girth(10))
、

点击查看代码
import rectangle as r
import circular as c
if __name__=='__main__':
print("圆形的周长为:",c.girth(10))
print("矩形的周长为:",r.girth(10,20))
、
运行结果:

- 实例03 在指定包中创建通用的设置和获取尺寸的模块

点击查看代码
_width=800
_height=600
def change(w,h):
global _width
_width=w
global _height
_height=h
def getWidth():
global _width
return _width
def getHeight():
global _height
return _height
、

点击查看代码
from settings.size import *
if __name__=='__main__':
change(1024,768)
print('宽度:',getWidth())
print('高度:',getHeight())
、
运行结果:

- 实例04 生成由数字、字母组成的4位验证码

点击查看代码
import random
if __name__=='__main__':
checkcode=""
for i in range(4):
index=random.randrange(0,4)
if index!=i and index+1!=i:
checkcode+=chr(random.randint(97,122))
elif index+1==i:
checkcode+=chr(random.randint(65,90))
else:
checkcode+=str(random.randint(1,9))
print("验证码:",checkcode)
、
运行结果:

- 实战一:大乐透号码生成器

点击查看代码
print("大乐透号码生成器")
import random
number=input("请输入要生成的大乐透号码注数:")
n=int(number)
for i in range(n):
QQ=random.sample(range(1, 36), 5)
HQ=random.sample(range(1,13),2)
print('{:0>2d}'.format(QQ[0]),'{:0>2d}'.format(QQ[1]),'{:0>2d}'.format(QQ[2]),'{:0>2d}'.format(QQ[3]),'{:0>2d}'.format(QQ[4]),"\t",'{:0>2d}'.format( HQ[0]),'{:0>2d}'.format(HQ[1]))
、
运行结果:

- 实战二:春节集五福

点击查看代码
import sys
sys.path.append(r"C:\Python\Python39\Lib")
import random
def Ji_Fu():
wf=['爱国福','富强福','和谐福','友善福','敬业福']
fu=random.sample(wf, 1)
return fu
def wf(fu):
print('当前拥有的福:')
for i, j in fu.items():
print(i,': ',j,'\t',end='')
def WuFu(fu):
type=1
for i, j in fu.items():
if j==0:
type=0
return type;
print('开始集福啦~~~')
wufu={'爱国福':0,'富强福':0,'和谐福':0,'友善福':0,'敬业福':0}
while WuFu(wufu)==0:
input('\n按下<Enter>键获取五福')
Strfu=Ji_Fu()[0]
print('获取到:' +Strfu)
wufu[Strfu] += 1
wf(wufu)
print('\n恭喜您集成五福!!!')
、
运行结果:

- 实战三:封装用户的上网行为

点击查看代码
import sys
sys.path.append(r"C:\Python\Python39\Lib")
def sw(time):
print('浏览网页',str(time)+'小时')
return time
def ksp(time):
print('看视频',str(time)+'小时')
return time
def wwlyx(time):
print('玩网络游戏',str(time)+'小时')
return time
def swxx(time):
print('上网学习',str(time)+'小时')
return time
def Time(time):
if time>8:
print("今天上网时间共计"+str(time)+"小时,请保护眼睛,合理安排上网时间!")
return time
import random
person='小明'
time=0
print(person,'上网时间、行为统计:')
time+=sw(1.5)
time+=ksp(2)
time+=wwlyx(3)
time+=swxx(2)
Time(time)
、
运行结果:

- 实战四:计算个人所得税

点击查看代码
import sys
sys.path.append(r"C:\Python\Python39\Lib")
def individual_income_tax(monthly_income):
'''由月收入计算个人所得税'''
Monthly_income=input("请输入月收入:")
Monthly_Income=int(Monthly_income)
Tax=Monthly_Income*(165/8000)
print('应纳个人所得税税额为{:.2f}'.format(Tax))
individual_income_tax(8000)
、
运行结果:

Python第八章实验报告的更多相关文章
- 20201123 实验二《Python程序设计》实验报告
20201123 2020-2021-2 <Python程序设计>实验报告课程:<Python程序设计>班级:2011姓名:晏鹏捷学号:20201123实验教师:王志强实验日期 ...
- 20212115 实验二 《python程序设计》实验报告
实验二 计算器设计 #20212115 2021-2022-2 <python程序设计> 实验报告二 课程: 课程:<Python程序设计>班级: 2121姓名: 朱时鸿学号: ...
- 20184302 实验三《Python程序设计》实验报告
20184302 2019-2020-2 <Python程序设计>实验3报告 课程:<Python程序设计> 班级: 1843 姓名: 李新锐 学号:20184302 实验教师 ...
- 20201123 实验三《python程序设计》实验报告
20201123 2020-2021-2 <python程序设计>实验三报告 课程:<Python程序设计>班级:2011姓名:晏鹏捷学号:20201123实验教师:王志强实验 ...
- 20201123 实验一《Python程序设计》实验报告
20201123 2020-2021-2 <Python程序设计>实验一报告 课程:<Python程序设计> 班级:2011班 姓名:晏鹏捷 学号:20201123 实验教师: ...
- 20202127 实验二《Python程序设计》实验报告
20202127 2021-2022-2 <Python程序设计>实验二报告 课程:<Python程序设计>班级: 2021姓名: 马艺洲学号:20202127实验教师:王志强 ...
- 20202127 实验一《Python程序设计》实验报告
20202127 2022-2022-2 <Python程序设计>实验一报告课程:<Python程序设计>班级: 2021姓名: 马艺洲学号:20202127实验教师:王志强实 ...
- 20212115 实验三 《python程序设计》实验报告
实验报告 20212115<python程序设计>实验三报告 课程:<Python程序设计>班级: 2121姓名: 朱时鸿学号:20212115实验教师:王志强老师实验日期:2 ...
- 20212115朱时鸿实验一《python程序设计》实验报告
------------恢复内容开始------------ #学号20212115 <python程序设计>实验一报告 课程: <python程序设计> 班级:2121 姓名 ...
- Python程序设计实验报告二:顺序结构程序设计(验证性实验)
安徽工程大学 Python程序设计 实验报告 班级 物流191 姓名 崔攀 学号3190505136 成绩 日期 2020.3.22 指导老师 修宇 [实验 ...
随机推荐
- 90、java ftp 读取文件
https://blog.csdn.net/qq_38380025/article/details/80679128
- Day 22 22.1:增量式爬虫
Day 22 22.1:增量式爬虫 爬虫应用场景分类 通用爬虫 聚焦爬虫 功能爬虫 分布式爬虫 增量式爬虫: 用来监测网站数据更新的情况(爬取网站最新更新出来的数据). 只是一种程序设计的思路,使用什 ...
- 肖sir__面试第十天课程__模拟面试讲解
一.面对面模拟面试1.打印好简历2.带好手机,录制自己回答的问题,总结,反思(内部),关闭手机和闹钟(外部)3.有笔试题,可以拍照发群里4.可以携带耳塞(适合女生)5.语速流程6.礼貌用语(面试官好, ...
- tomcat各个版本下载
官网地址:https://archive.apache.org/dist/tomcat/
- js对象中的set和get方法
在js中,每个对象都有set和get方法,也可以自己进行定义,这里先简单说下用法 var person = { _name:'小花', get name() { return this._name + ...
- ESP8266-01S 烧录AT固件
首先就是下载官网的下载软件和AT固件 这是下载好了的 然后就是硬件电路了 我是想把ESP8266用于Ardiuno板子的,然后网上有说买的USBTOTTL的3v3供电不够,所以我就用的Ardiuno板 ...
- Leecode-每日一题-题目448. 找到所有数组中消失的数字
今天重新开始刷leecode 为了致敬我的偶像,还是选择把做题笔记发在博客园上 题目448. 找到所有数组中消失的数字 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数 ...
- mark一下,python2.7版本不能直接print中文字符串,3.0以上的版本是可以的
mark一下,python2.7版本不能直接print中文字符串,3.0以上的版本是可以的
- AutoCAD2018
「AutoCAD_2018_SC.exe」https://www.aliyundrive.com/s/GvpR9yg6TWg 点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线 ...
- Spring5框架
Spring5框架 一.Spring框架概述 1.1 Spring框架简介 Spring是一个开源框架,它由Rod Johnson创建.它是为了解决企业应用开发的复杂性而创建的.Spring使用基本的 ...