習題35,分支和函式,笨方法學python

2021-07-27 21:41:42 字數 2331 閱讀 8541

#coding=utf-8

from sys import exit

defgold_room

():print

"this room is full of gold. how much do you take?"

next = raw_input(">")

if"0"in next or

"1"in next:

how_much = int(next)

else:

dead("man, learn to type a number.")

if how_much < 50:

print

"nice, you are not greedy, you win!"

exit(0)

else:

dead("you greedy bastard!")

defbear_room

():print

"there's bear here."

print

"the bear has a bunch of honey."

print

"the fat bear is in front of another door."

print

"how are you going to move the bear?"

bear_moved = false

while

true:

next = raw_input(">")

if next == "take honey":

dead("the bear looks at you then slaps your face off.")

elif next == "taunt bear"

andnot bear_moved:

print

"the bear has moved from the door. you can go through it now."

bear_moved = true

elif next == "taunt bear"

and bear_moved:

dead("the bear gets pissed off and chews your leg off.")

elif next == "open door"

and bear_moved:

gold_room()

else:

print

"i got no idea what that means."

defcthulhu_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?"

next = raw_input(">")

if"flee"

in next:

start()

elif

"head"

in next:

dead("well that was tasty!")

else:

cthulhu_room()

defdead

(why):

print why, "good job"

exit(0)

defstart

():print

"you are in a dark room."

print

"there is a door to your right and left."

print

"which one you take?"

next = raw_input(">")

if next == "left":

bear_room()

elif next == "right":

cthulhu_room()

else:

dead("you stumble around the room until you starve.")

start()

#程式可以執行,但是測試輸入資料時,沒反應,說明**格式又錯誤,檢查。

note:

1) exit(0) 表示程式正常推出。

2) exit(1)表示程式出現錯誤。

3) exit(100)來表示 和exit(2), exit(3)不同的錯誤。

笨辦法學python習題35分支和函式

這個學期的課太多了,我以後盡量做到至少一周一更吧,開始今天的學習吧 指令碼執行結果如下 這個指令碼 挺長的,截了兩次圖,不過這個文字編排做的挺好的,自動幫我右對齊了。這個 和之前的某一章挺像,也是乙個那種文字選擇遊戲。附加練習 1.把這個遊戲的地圖畫出來,把自己的路線也畫出來。答 這個能畫,不過可能...

《笨方法學 Python 3》35 分支和函式

from sys import exit def gold room print this room is full of gold.how much do you take?這個房間裡滿是金子。你要多少錢?choice input if 1 or 0 in choice how much int ...

練習35 分支和函式

coding utf 8 ex35 分支和函式 from sys import exit defgold room print this room is full of gold.how much do you take?next input 原判斷 if 0 in next or 1 in nex...