• 案例ATM


    #=========================================
    print("ATM案例".center(60,"*"))
    """
    0退出
    1登录
    2转账
    3查询
    4提现
    5注册
    """
    def quit():
    print("欢迎下次使用")
    def login():
    print("登录功能")
    def transfer():
    print("转账功能")
    def check_balance():
    print("查询功能")
    def withdraw():
    print("提现功能")
    def register():
    print("注册功能")
    dic={
    "0":("退出",quit),
    "1":("登录",login),
    "2":("转账",transfer),
    "3":("查询",check_balance),
    "4":("提现",withdraw),
    "5":("注册",register)
    }
    while True:
    for i in dic:
    print("{}:{}".format(i,dic[i][0]).center(60," "))
    cmd=input("输入操作的序号:").strip()
    if not cmd.isdigit():
    print("小朋友,请输入数字序号!")
    if cmd in dic:
    dic[cmd][1]()
    else:
    print("你输入的命令不存在")
    # 函数嵌套
    # 1.函数的嵌套调用:在调用一个函数的过程中又调用另一个函数
    def max2(x,y):
    if x>y:
    return x
    else :
    return y
    def max4(a,b,c,d):
    res1=max2(a,b)
    res2=max2(res1,c)
    res3=max2(res2,d)
    return res3
    res=max4(11,12,23,44)
    print(res)
    # 2.函数的嵌套定义:在函数内定义其他函数
    def f1():
    def f2():
    pass
    # =================求圆的周长和面积案例==============
    print("求圆的周长和面积案例".center(60,"="))
    def circle(r,count=0):
    from math import pi
    def length(r):
    return 2*pi*r
    def area(r):
    return length(r)
    if count==0:
    return 2*pi*r
    if count==1:
    return area(r)
    res=circle(2,1)
    print(res)
  • 相关阅读:
    c#声明数组
    【游戏物理】欧拉、龙格、韦尔莱
    当const放在function声明后
    【物理】AABB物理碰撞检测
    100 Path Sum
    Loop Unrolling 循环展开
    Unity Shader and Effects Cookbook问题记录
    【ShaderToy】画一个球体
    pymysql
    mysql表间的关系和查询
  • 原文地址:https://www.cnblogs.com/mayrain/p/12548668.html
Copyright © 2020-2023  润新知