笨方法学python
习题35.36
from sys import exit
def gold_room():
print("This room is full of gold. How much do you take?")
choice = input("> ")
if "0" in choice or "1" in choice:
how_much = int(choice)
else:
dead("Man, learn to type a number.")
if how_much < 50:
print("Nice, you're not qreedy, you win!")
exit(0)
else:
dead("You qreedy bastard!")
def bear_room():
print("There is a bear here.")
print("The bear is a bounch of money.")
print("The fat bear is in front of another door.")
print("How are you going to move the bear?")
bear_moved = False
while True:
choice = input("> ")
if choice == "take money":
dead("The bear looks at you then slaps your face off.")
elif choice == "taunt bear" and not bear_moved:
print("The bear has moved from the door.")
print("You can go through it now.")
bear_moved = True
elif choice == "taunt bear" and bear_moved:
dead("The bear gets pissed off and chews your leg off.")
elif choice == "open door" and bear_moved:
gold_room()
else:
print("I got no idea what that means.")
def cthulhu_room():
print("Here you see the great evil Cthulhu.")
print("He, it, whatever stares at you and you go insane.")
print("Do you flee for your life or eat your head?")
choice = input("> ")
if "flee" in choice:
start()
elif "head" in choice:
dead("Well that was tasty.")
else:
cthulhu_room()
def dead(why):
print(why, "Good job!")
exit(0)
def start():
print("You are in a dark home.")
print("There is a door to your right and left.")
print("Which one do you take?")
choice = input("> ")
if choice == "left":
bear_room()
elif choice == "right":
cthulhu_room()
else:
dead("You stumble around the room unyil you starve.")
start()
运行结果:
习题35类似一个闯关小游戏,有着不同的岔路口。不同的选择,通往不同的道路。我所走的只是一条。总体就是创建函数(建立一道通往后续结果的门),if语句和while语句就是建立产路口,让你做出选择。
1.把这个游戏的地图都画出来。
我是在纸上画的,这里借鉴了别人的:
————————————————
借用了这位大佬的图:
原文链接:https://blog.csdn.net/u011692485/article/details/76851101
习题36
from sys import exit
def 大学():
print("恭喜你踏入大学的殿堂!")
print("你所能负担的学费是多少?10000以内还是以上?")
choice = input("> ")
学费 = int(choice)
if 学费 < 10000:
print("你选择的专业是计算机还是材料?")
专业 = input("> ")
if 专业 == "计算机":
print("明智的选择,经过四年的学习,你找到了一个高薪工作。")
exit(0)
elif 专业 == "材料":
dead("唉,你进入了天坑专业,未来的路没有那么好走。")
else:
dead("未来由你自己掌控。")
elif 学费 > 10000:
dead("恭喜你可以选择金融专业。从这所名牌大学毕业你可以得到一个很好的前程。")
else:
dead("拜拜。")
def 高考():
print("你即将面临人生中最公平的一次考试。")
print("未来的路很大程度上将从此开始截然不同。")
print("你会有下面几种结果:失败,高分,录取。请选择:")
命运 = False
while True:
结果 = input("> ")
if 结果 == "失败":
print("你还可以在选择辍学或者二战。")
选择 = input("> ")
if 选择 == "辍学":
打工()
elif 选择 == "二战":
高考()
else:
dead("阿巴阿巴!")
elif 结果 == "高分" and not 命运:
print("恭喜你!你可以填报学校了。")
命运 = True or False
elif 结果 == "高分" and 命运:
dead("很抱歉你滑档了!")
elif 结果 == "录取" and 命运:
大学()
else:
dead("我累了!")
def 打工():
dead("奋斗吧少年!")
def dead(why):
print(why, "祝你好运。")
exit(0)
def start():
print("这里有两个选择,一个是上学,一个是辍学。")
print("你想选哪个?")
选择 = input("> ")
if 选择 == "上学":
高考()
elif 选择 == "辍学":
打工()
else:
dead("我也不知道会发生什么。")
start()
运行结果:
我这个纯属模仿习题35,建议大家先编好小故事在进行创作。