笨办法学Python3 习题31 作出决定

可以在if语句里面放if语句创建嵌套的决定

  • 有多的选项,中间多写几个elif 就行

写一个小脚本冒险选择游戏

 1 print("""You enter a dark room with two doors.   
 2 Do you go through door #1 or door#2?""") # 打印 你进入一个有两扇门的暗室。你是从1号门走还是从2号门走?
 3 
 4 door = input("这边输入门号>")              # 用户输入门号选择
 5 
 6 if door == "1":
 7     print("""There's a giant bear here eating a cheese cake.
 8     What do you do? 
 9     1.Take the cake.
10     2.Scream at the bear.""")            # 这里有一只大熊在吃奶酪蛋糕。你需要做什么?1.拿蛋糕。2.对着熊尖叫。
11 
12     you_do = input("这边输入选择>")        #用户输入选择             
13 
14     if you_do == "1":
15         print("The bear eats your face off. Good job!")   # 打印 熊吃掉了你的脸。干得好。
16     elif you_do == "2":
17         print("The bear eats your legs off. Good job!")   # 打印 熊吃掉了你的腿。干得好。
18     else:
19         print(f"Well,doing {you_do} is probably better.") # 打印 嗯,做选项{XX} 可能更好
20         print("Bear runs away.")                          # 打印 熊逃跑了
21 
22 elif door == "2":
23     print("""You stare into the endless abyss at Cthulhu's retina.
24     1. Blueberries.
25     2. Yellow jacket clotespins.
26     3. Undersatanding revolvers yelling melodies.""")# 打印 你凝视着克苏鲁眼底无尽的深渊。1.蓝莓。2.黄色夹克衫。
27                                                      #3.水下左轮手枪大喊旋律
28 
29     insanity = input("选择你的幻觉>")    # 用户输入选择
30 
31     if insanity == "1" or insanity =="2":
32         print("""Your body survives powered by a mind of jello.
33         Good job!""")                  # 打印 你的身体靠果冻的力量生存,干得好!
34 
35     else:
36         print("""The insanity rots your eyes into a pool of muck.
37         Good job!""")                  # 打印 这种疯狂会把你的眼睛腐蚀成一滩渣渣,干得好!
38 
39 else:
40     print("You stumble around and fall on a knife and die. Good job!")
41                                        # 打印 你跌跌撞撞倒在刀上就死了。干得好!
PS C:\Users\Administrator\lpthw> python ex31.py
You enter a dark room with two doors.
Do you go through door #1 or door#2?
这边输入门号>2
You stare into the endless abyss at Cthulhu's retina.
    1. Blueberries.
    2. Yellow jacket clotespins.
    3. Undersatanding revolvers yelling melodies.
选择你的幻觉>1
Your body survives powered by a mind of jello.
        Good job!
PS C:\Users\Administrator\lpthw> python ex31.py
You enter a dark room with two doors.
Do you go through door #1 or door#2?
这边输入门号>2
You stare into the endless abyss at Cthulhu's retina.
    1. Blueberries.
    2. Yellow jacket clotespins.
    3. Undersatanding revolvers yelling melodies.
选择你的幻觉>2
Your body survives powered by a mind of jello.
        Good job!
PS C:\Users\Administrator\lpthw> python ex31.py
You enter a dark room with two doors.
Do you go through door #1 or door#2?
这边输入门号>2
You stare into the endless abyss at Cthulhu's retina.
    1. Blueberries.
    2. Yellow jacket clotespins.
    3. Undersatanding revolvers yelling melodies.
选择你的幻觉>3
The insanity rots your eyes into a pool of muck.
        Good job!
PS C:\Users\Administrator\lpthw> python ex31.py
You enter a dark room with two doors.
Do you go through door #1 or door#2?
这边输入门号>1
There's a giant bear here eating a cheese cake.
    What do you do?
    1.Take the cake.
    2.Scream at the bear.
这边输入选择>1
The bear eats your face off. Good job!
PS C:\Users\Administrator\lpthw> python ex31.py
You enter a dark room with two doors.
Do you go through door #1 or door#2?
这边输入门号>1
There's a giant bear here eating a cheese cake.
    What do you do?
    1.Take the cake.
    2.Scream at the bear.
这边输入选择>2
The bear eats your legs off. Good job!
PS C:\Users\Administrator\lpthw> python ex31.py
You enter a dark room with two doors.
Do you go through door #1 or door#2?
这边输入门号>1
There's a giant bear here eating a cheese cake.
    What do you do?
    1.Take the cake.
    2.Scream at the bear.
这边输入选择>3
Well,doing 3 is probably better.
Bear runs away.

 

posted @ 2023-10-09 18:23  萹豆  阅读(7)  评论(0编辑  收藏  举报