首页 > 编程语言 >python8

python8

时间:2022-11-24 16:45:23浏览次数:41  
标签:__ weight checkcode person height width python8

一、创建计算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个元素的列表,
分别为姓名、身高(单位:米)和体重(单位:千克)
'''

二、导入两个包括同名函数的模块

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

 三、在指定包中创建通用的设置和获取的模块

_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

 

四、生成由数字、字母组成的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,99))
else:
checkcode +=str(random.randint(1,9))
print("验证码:",checkcode)

 

 

标签:__,weight,checkcode,person,height,width,python8
From: https://www.cnblogs.com/666k/p/16922336.html

相关文章

  • python8 集合
    集合介绍Python内置的数据结构和列表、字典一样都属于可变类型的序列集合是没有Value的字典,【即只存在Key】类型:set创建直接{}创建,用,号分隔内置函数set......