ex35 分支和函数

这是一个简单的游戏,主要是使用了函数的定义,不同的分支调用

from sys import exit         #exit(0)无错误退出,exit(1)有错误退出

def gold_room():
    print("This room is full of gold,how much do you want to take?")
    next = input('>')
    if '0' in next or '1' in next:
        how_much = int(next)  #把next改为整型
    else:
        dead("Man,learn to type a number.")
    
    if how_much < 50:
        print("Great,you're not greedy.")
        exit(0)             
    else:
        dead("You greedy bastard.")
    
def bear_room():
    print("There is a bear here with lots of money.")
    print("The fat bear is in front of another door,how are you going to move the bear?")
    bear_moved = False      #把bear_moved定义成false,也即熊在前面
    while True:             #这里可以重复下面的循环,直到dead或gold_room才有exit
        next = input('>')
        if next == "take money":
            dead("The bear looks at you and slaps your face off.")
        elif next == "taunt bear" and not bear_moved:       #恐吓熊,使其离开
            print("The bear has moved from the door,you can go through it now.")
            bear_moved = True         #此时熊已经离开,将其定义为离开即可,但是这个True只在这个elif里面生效
        elif next == "taunt bear" and bear_moved:           #恐吓熊,但它并没有离开
            dead("The bear will eat your leg.")
        elif next == "open door" and bear_moved:       #这里要确保taunt bear使得bear_moved为True之后才能执行gold_room函数
            gold_room()
        else:
            print("I got no idea what the means.")
    
def cthulhu_room():
    print("Here you see the great evil Cthulhu.")
    print("You are dangerous.")
    print("Do you flee for your life or eat your head?")
    next = input('>')
    if "flee" in next:
        start()           #调用start函数
    elif "head" in next:
        dead("It's tasty!")
    else:                   #输入其他内容则重新执行函数
        cthulhu_room()

#dead()是被调用到的函数 
def dead(why):          #dead函数的作用是返回参数本身,然后退出
    print(why,"Good job.")
    exit(0)

def start():
    print("You are in a dark room.")
    print("There is a door to your left and right.")
    print("Which one do you take?")
    next = input('>')
    if next == "left":
        bear_room()
    elif next == "right":
        cthulhu_room()
    else:
        print("You stumble around the room until you starve")

start()

运行结果

PS E:\tonyc\Documents\Vs workspace> cd ‘e:\tonyc\Documents\Vs workspace’; ${env:PYTHONIOENCODING}=‘UTF-8’; ${env:PYTHONUNBUFFERED}=‘1’; & ‘D:\Anboot\Python\python.exe’ ‘c:\Users\tonyc.vscode\extensions\ms-python.python-2019.3.6558\pythonFiles\ptvsd_launcher.py’ ‘–default’ ‘–client’ ‘–host’ ‘localhost’ ‘–port’ ‘49227’ ‘e:\tonyc\Documents\Vs workspace\The Hard Way\ex35(分支和
函数).py’
You are in a dark room.
There is a door to your left and right.
Which one do you take?
left
There is a bear here with lots of money.
The fat bear is in front of another door,how are you going to move the bear?
taunt bear
The bear has moved from the door,you can go through it now.
open door
This room is full of gold,how much do you want to take?
30
Great,you’re not greedy.

当然,还有很多一些情况没有完全体现出来,具体流程如下
在这里插入图片描述

内容概要:本文详细分析了全球及中国财富管理市场的发展现状与未来趋势。全球财富管理市场起源于欧洲、发展于美国,美国财富管理市场经过百年发展,形成了以商业银行、综合财富管理平台投资服务平台为代表的三类财富管理体系。中国财富管理市场正处于快速发展期,居民财富快速增长并向金融资产倾斜,资管新规引导市场健康发展。文中还探讨了中国财富管理市场的竞争格局,包括私人银行、银行理财、公募基金、券商资管、信托、第三方财富管理机构互联网财富管理平台的发展情况。此外,公募基金投顾试点成为财富管理市场转型的重要探索,买方投顾模式逐步取代卖方投顾模式,AI赋能投顾业务,为行业发展带来新机遇。 适合人群:对财富管理行业感兴趣的投资者、金融从业者及研究机构。 使用场景及目标:①了解全球及中国财富管理市场的发展历程与现状;②掌握中国财富管理市场竞争格局及各机构的发展特点;③探索公募基金投顾试点对财富管理市场的转型意义及AI赋能投顾业务的应用前景。 阅读建议:本文内容详实,涵盖了财富管理市场的多个方面,建议读者重点关注中国财富管理市场的现状与发展趋势,特别是私人银行、银行理财、公募基金、券商资管等机构的具体发展情况,以及公募基金投顾试点AI赋能投顾业务的创新模式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值