首页 > 其他分享 >Chapter 8

Chapter 8

时间:2022-12-13 12:33:40浏览次数:28  
标签:Chapter __ height str time print def

Bmi

bmi.py
def fun_bmi(person,height,weight):
    print(person+'的身高'+str(height)+'米\t 体重:'+str(weight)+'千克')
    bmi=weight/(height*height)
print(person+'的BMI指数为:'+str(bmi))

bmi_.py
import bmi
bmi.fun_bmi('jm',175,100)

实例2

rectangle.py
def girth(width,height):
    return (width+ height)*2
def area(width,height):
    return width*height
if __name__=='__main__':
print(area(10,20))

circular.py
import math
PI=math.pi
def girth(r):
    return round(2*PI*r,2)

def area(r):
    return round(PI*r*r,2)
if __name__=='__main__':
print(girth(10))

compute.py
import rectangle as r
import circular as c
if __name__=='__main__':
    print('圆形的周长为:',c.girth(10))
print('矩形的周长为:',r.girth(10,20))

Size

Settings.size.py
__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

main.py
from settings.size import *
if __name__=='__main__':
    change(1024,768)
    print('宽度:',getWidth())
print('高度:',getHeight())

Checkcode

checkcode.py
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)

 

Project

#实战1
import random
def number():
    numbers=[]
    leftlist=list(range(1,36))
    leftnumber=random.sample(leftlist,5)
    rightlist=list(range(1,13))
    rightnumber=random.sample(rightlist,2)
    leftnumber.sort()
    rightnumber.sort()
    numbers=leftnumber+rightnumber
    template='{:0>2d} {:0>2d} {:0>2d} {:0>2d} {:0>2d}   {:0>2d} {:0>2d}'
    numbers=template.format(numbers[0],numbers[1],numbers[2],numbers[3],numbers[4],numbers[5],numbers[6])
    print(numbers)


print('大乐透号码生成器')
while True:
    a=int(input('请输入要生成的大乐透号码注数:'))
    for i in range(a):
        number()
        print('')
    break
#实战2
import random
five_blessings=['爱国福','富强福','和谐福','友善福','敬业福']
print('开始集福啦~~~')
def collect_blessings():
    a=0
    f=0
    h=0
    y=0
    j=0
    while True:
        input('按下<enter>键获取五福')
        choice=random.choice(five_blessings)
        print('获取到'+choice)
        print('当前拥有的福:')
        if choice=='爱国福':
            a+=1
            print('爱国福:\t'+str(a)+'富强福:\t'+str(f)+'和谐福:\t'+str(h)+'友善福:\t'+str(y)+'敬业福:\t'+str(j))
        elif choice=='富强福':
            f+=1
            print('爱国福:\t'+str(a)+'富强福:\t'+str(f)+'和谐福:\t'+str(h)+'友善福:\t'+str(y)+'敬业福:\t'+str(j))
        elif choice=='和谐福':
            h+=1
            print('爱国福:\t'+str(a)+'富强福:\t'+str(f)+'和谐福:\t'+str(h)+'友善福:\t'+str(y)+'敬业福:\t'+str(j))
        elif choice=='友善福':
            y+=1
            print('爱国福:\t'+str(a)+'富强福:\t'+str(f)+'和谐福:\t'+str(h)+'友善福:\t'+str(y)+'敬业福:\t'+str(j))
        else:
            j+=1
            print('爱国福:\t'+str(a)+'富强福:\t'+str(f)+'和谐福:\t'+str(h)+'友善福:\t'+str(y)+'敬业福:\t'+str(j))

collect_blessings()
#实战3
Net.py
def web(time):
    print('浏览网页:'+str(time)+'小时;')
    return time
def video(time):
    print('看视频:'+str(time)+'小时;')
    return time
def playgame(time):
    print('玩网络游戏:'+str(time)+'小时;')
    return time
def study(time):
    print('上网学习:'+str(time)+'小时;')
    return time
def total(time):
    print('今天上网时间共计:'+str(time)+'小时;',end=' ')
    if time>=8:
        print('请保护眼睛,合理安排上网时间')
    else:
        print('比较合理,注意休息')

Net_1
import Net
name='小明'
print(name,'上网时间,行为统计')
t1=Net.web(1.5)
t2=Net.video(2)
t3=Net.playgame(3)
t4=Net.study(2)
time=t1+t2+t3+t4
Net.total(time)
#实战4
Tax.py
def tax(monthmoney):
    ds=3500
    baoxian=7662
    yanglao=monthmoney*0.08
    yiliao=monthmoney*0.02
    shiye=monthmoney*0.005
    housem=monthmoney*0.12
    demoney=yanglao+yiliao+shiye+housem
    if demoney>=7662:
        demoney>=7662
    lastmoney=monthmoney-demoney-ds
    if lastmoney<=0:
        taxes=0
    elif 0<lastmoney<1500:
        taxes=lastmoney*0.03
    elif 1500<=lastmoney<4500:
        taxes=lastmoney*0.1-105
    elif 4500<=lastmoney<9000:
        taxes=lastmoney*0.2-555
    elif 9000<=lastmoney<35000:
        taxes=lastmoney*0.25-1005
    elif 35000<=lastmoney<55000:
        taxes=lastmoney*0.3-2002
    elif 55000<=lastmoney<80000:
        taxes=lastmoney*0.35-5505
    elif 80000<=lastmoney:
        taxes=lastmoney*0.45-13505
return taxes
taxes.py
import tax
m=float(input('请输入您的月收入总额:'))
taxes=tax.tax(m)
print('您应收个人所得税金额为:{:.2f}元'.format(taxes))

 

标签:Chapter,__,height,str,time,print,def
From: https://www.cnblogs.com/Kyaria-code-test/p/16978250.html

相关文章

  • Chapter 6
    Function_tipsdeffunction_tips():importdatetimemot=["今天星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择。","今天星期二:\n含泪播种的......
  • Chapter 4
    Datetimeimportdatetime#定义一个列表mot=["今天星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择。","今天星期二:\n含泪播种的人一定能笑着收获。",......
  • Chapter6_与数据结构称为好朋友的七个要点
    热身问答程序中的变量是指什么?变量是数据的容器。变量中所存储的数据是可以改变的。变量的实质是按照变量所存储数据的大小被分配到的一块内存空间。把若干个数据......
  • Chapter5_与算法成为好朋友的七个要点
    热身问答Algorithm翻译成中文是什么?算法辗转相除法是用于计算什么的算法?是用于计算最大公约数的算法。最大公约数指的是两个整数的公共约数中最大的数。使用辗转......
  • Chapter7_成为会使用面向对象编程的程序员吧
    理解面向对象编程热身问答Object翻译成中文是什么?对象对象(Object)是表示事物的抽象名词。OOP是什么的缩略语?ObjectOrientProgramming面向对象也可以简称......
  • Chapter8_一用就会的数据库
    热身回答数据库术语中的“表”是什么意思?table,表示数据的集合表(Table)就是被整理成表格形式的数据一张表由若干个列和行构成。列也被称为字段(Field),行也被称为记录(Re......
  • Chapter9_通过七个简单的实验理解TCP_IP网络
    热身问答LAN是什么的缩略语?LAN是LocalAreaNetwork(局域网)的缩略语。通常把在一栋建筑物内或是一间办公室里的那种小规模网络称作LAN。与此相对,把互联网那样......
  • Chapter11_XML究竟是什么
    热身回答XML是什么的缩写?Extensiblemarkuplanguage可扩展标记语言所谓标记语言,就是可以用标签为数据赋予意义的语言。HTML和XML的区别是什么?HTML是网页,X......
  • Chapter10_试着加密数据吧
    热身问答通常把还原加密过的文件这一操作叫作什么?解码解密在字母A的字符编码上加上3,可以得到哪个字母?D因为字母表中的字母编码是按字母顺序排列的,所以在字母......
  • Chapter12_SE负责监管计算机系统的构建
    热身问答SE是什么的缩略语?SE是SystemEngineer(系统工程师)的缩略语。在计算机系统的开发过程中,SE是参与所有开发阶段的工程师。IT是什么的缩略语?Information......