黑马程序员python教程,8天python从入门到精通,学python看这套就

#黑马程序全课程案例(持续更新中......) #P40【猜数游戏】 #引入随机数生成模块 import random #设置随机数生成范围(min——max) number_min=int(input("输入想猜测数的最小值:")) number_max=int(input("输入想猜测数的最大值:")) freedom=random.randint(number_min,number_max) num=int(input("输入你猜测的数字:")) #猜测次数统计 totle=1 #条件判断及循环 while(num!=freedom): if (num > freedom): num = int(input("你猜大了\n请继续输入:")) totle+=1 elif(num< freedom): num = int(input("你猜小了\n请继续输入:")) totle+=1 if(num!=freedom and totle==3): print("已猜三次,未猜中,YOU LOST!!!") break if (num == freedom): print("恭喜你猜对了") #p42【九九乘法表输出三种思路】 print("while循环思路一////////////////////////////////////////////////////////////////") i=1 while i<=9: j=1 while j<=i: print(f"\t{j}×{i}={j*i}",end='') j+=1 i+=1 print() print("while循环思路二///////////////////////////////////////////////////////////////////") a=0 while a<9: a+=1 b=0 while b<a: b+=1 print(f"\t{b}×{a}={a*b}",end='') print() print("for循环//////////////////////////////////////////////////////////////////////////") for x in range(1,10): for y in range(1,x+1): print(f"\t{y}×{x}={y*x}",end='') print() #p44【字符串中字符查询】 text=input("输入一段内容:") find_text=input("输入你想查询的字符:") totle=0 for text_number in text: if text_number==find_text: totle+=1 print(f'该内容中有【{totle}】个"{find_text}"') #P50【公司发放工资】 import random money_totle=int(input("输入公司余额:")) people=int(input("输入员工人数:")) #员工编号 num_people=0 #绩效随机生成 for x in range(1,people+1): if money_totle>=1000: num_people += 1 grand = random.randint(1, 10) if grand<5: money_totle=money_totle print(f"{num_people}号员工绩效为{grand}分,绩效低不发工资,公司剩余余额{money_totle}") continue else: money_totle-=1000 print(f"{num_people}号员工绩效为{grand}分,发工资1000元,公司剩余余额{money_totle}") else: print("公司余额不足,下个月再发") break
#p61黑马【ATM】
money=5000000 def charge(): """ 此函数用于查询余额 """ print(f"{name}您好,您当前余额为:{money}") exit(menu()) def deposit(): """ 此函数用于存款 """ amount=int(input("请输入存款数额:")) global money money=money+amount print(f"存款成功,当前余额为:{money}元") exit(menu()) def withdraw(): """ 此函数用于取款 """ global money amount = int(input("请输入取款数额:")) if amount>money: print("当前余额不足,无法完成此操作") exit(menu()) else: money = money - amount print(f"取款成功,当前余额为:{money}元") exit(menu()) def menu(): """ 此函数为主菜单 """ action=int(input("请输入您想进行操作对应的数字\n1.查询余额\n2.存款\n3.取款\n4.退卡\n")) if action==1: charge() elif action==2: deposit() elif action==3: withdraw() elif action==4: print("退卡成功") exit(0) else: print("erro:输入错误,请重新输入") exit(menu()) name=input("请输入您的名字:") menu()
#P53函数的调用
def void (): print("欢迎来到黑马程序员\n请出示你的健康码") void()
#P55函数形参及实参
def void(x) : print("欢迎来到黑马程序员,请出示健康码,并配合体温检测") if x<=37.5: print(f"体温检测中......\n你的体温是{x}度,体温正常,请进!") else: print(f"体温检测中......\n你的体温是{x}度,体温异常,需要隔离!") void(38.2)