《笨辦法學python》加分習題35 我的答案

2021-08-07 18:33:42 字數 2531 閱讀 5982

這是我自己學習的答案,會盡力寫的比較好。還望大家能夠提出我的不足和錯誤,謝謝!

ex34我沒有什麼想法,所以就不更這個。

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're not greedy, you win!"

exit(0)

else:

dead("you greedy bastard!")

defbear_room

():print

"there is a 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 do you take?"

next = raw_input("> ")

if next == "left":

bear_room()

elif next == "right":

cthulhu_room()

else:

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

start()

裡面import了sys.exit(),就是在這段**結束後退出整個程序。

遊戲是房間探險遊戲,其實我覺得最好做點提示會比較好 。

3、文件註解使用 「」」 內容自擬 「」」 來寫。

4、暫時沒有思路

5、當鍵入值不存在1或者0時,它就認為鍵入值不是數字。使用str.isdigit()解決。if next.isdigit():

笨辦法學python加分習題30

python版本 3 若有錯誤,敬請指出 模組名稱 測試.py 加分習題30 people 30 cars 40 buses 15 if cars people print we should take the cars.elif cars people print we should not ta...

笨辦法學python加分習題36

python版本 3 若有錯誤,敬請指出 模組名稱 測試.py 我可能是個傻姑娘.加分習題36 def a print 吃西紅柿炒蛋時,你常常煩惱是該先吃西紅柿還是先雞蛋嗎?print a 是 nb 否 answer input if answer.upper a b elif answer.upp...

笨辦法學python加分習題38

python版本 3 若有錯誤,敬請指出 模組名稱 測試.py 加分習題38 states cities cities ny new york cities or portland print 10,1 print ny stae has cities ny print or state has c...