:# 建立無限迴圈
next
=input
(">")if
next
=="take honey"
: dead(
"the bear looks at you then slaps your face off."
)elif
next
=="taunt bear"
andnot bear_moved:
("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
("i got no idea what that means."
)def
cthulhu_room()
("here you see the great evil cthulhu."
("he, it, whatever stares at you and you go insane."
)next
=input
(">")if
"flee"
innext
: start(
)elif
"head"
innext
: dead(
"well that was tasty!"
)else
: cthulhu_room(
)def
dead
(why)
(why,
"good job!"
) exit(0)
defstart()
("you are in a dark room."
("there is a door to your right and left."
("which one do you take?"
)# 輸入值並賦給next,若next是left呼叫bear_room,若next是right呼叫cthulhu_room,若其它,不進入房間
next
=input
(">")if
next
=="left"
: bear_room(
)elif
next
=="right"
: cthulhu_room(
)else
: dead(
"you stumble around the room until you starve."
)start(
)exit(0)可以中斷某個程式,且表示程式是正常退出的。
exit(1)表示發生錯誤而導致的中斷。可以用不一樣的數字表示不同的錯誤結果,例如可以用exit(100)來表示另一種和exit(2)或exit(1)不同的錯誤。
while true可以建立無限迴圈。
練習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...
習題35,分支和函式,笨方法學python
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 ...
笨辦法學python習題35分支和函式
這個學期的課太多了,我以後盡量做到至少一周一更吧,開始今天的學習吧 指令碼執行結果如下 這個指令碼 挺長的,截了兩次圖,不過這個文字編排做的挺好的,自動幫我右對齊了。這個 和之前的某一章挺像,也是乙個那種文字選擇遊戲。附加練習 1.把這個遊戲的地圖畫出來,把自己的路線也畫出來。答 這個能畫,不過可能...