python笨辦法學python習題

2021-03-04 02:29:24 字數 5190 閱讀 6284

1樓:

if "0" in next or "1" in next:

如果你輸入數字不包含1,0則會man,輸入一個數字

2樓:小眼睛男生

你只是寫了一個方法,要呼叫這個方法gold_room(),才能執行你的程式

新手求教,笨方法學python的習題35問題

3樓:匿名使用者

#!usr/bin/python

# -*-coding:utf-8-*-

from sys import exit

def gold_room():

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

next = 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!")

def bear_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 = input("> ")

if next == "take honey":

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

elif next == "taunt bear" and not 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.")

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

next = input("> ")

if "flee" in next:

start()

elif "head" in next:

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 room.")

print ("there is a door to your right and left.")

print ("which one do you take?")

next = input("> ")

if next == "left":

bear_room()

elif next == "right":

cthulhu_room()

else:

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

start()

執行結果如下:

you are in a dark room.

there is a door to your right and left.

which one do you take?

> left

there is a bear here.

the bear has a bunch of honey.

the fat bear is in front of another door.

how are you going to move the bear?

> taunt bear

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

> open door

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

> asf

man, learn to type a number. good job!

python 笨辦法學python 習題38

4樓:

__init__方法在類的一個物件被建立時,馬上執行。這個方法可以用來對你的物件做一些你希望專的 初始化屬 。注意,這個名稱的開始和結尾都是雙下劃線。

建立def __init__(self,lyrics): 或者別的函式時候需要多加一個self變數:

如果不加self,lyrics= lyrics這樣的**意義就不明確了,它指的既可能例項的lyrics屬性,或者一個叫做lyrics的區域性變數。有了self.lyrics=lyrics你就知道這指的是例項的屬性self.

lyrics

5樓:**ile無峰

物件導向初始bai值du

賦值aa = song(["they rally around the family",

"with pockets full of shells"])aa唱的歌詞

zhi就是那個數列

lyrics 歌詞的dao意思吧

笨辦法學python,習題25import出錯

6樓:匿名使用者

兩種處理:

1、切換

來到源ex25.py的路徑下,再import。切換路徑命令:cd f:\pylearning

2、把ex25.py檔案複製到python安裝目錄的lib資料夾下面,在任意位置都可以import

7樓:匿名使用者

在敲入python之前,先復f:\ 回車制,然後再 cd f:\pylearning,再輸入python, 這樣就不會報錯了。

或者你在進入python提示後,import os, 然後輸入os.chdir('f:\\pylearning'), 再輸入import ex25就不會報錯了。

8樓:匿名使用者

當沒有切換到f:/pylearning時,不會從改目錄下查詢。需要切換到該目錄再import

9樓:匿名使用者

這個實際就是一復個制環境變數的問題,你把你寫

bai 的python檔案所

笨辦法學python第三版,43題我怎麼得不到習題結果,求指教

10樓:匿名使用者

你跟我用的肯定是同一個pdf,坑爹的是程式沒印全。

原程式在learn python the hard way,ex41,敲完就有了。。。

笨辦法學python 習題15報錯

11樓:你爸夏洛克

c:\users\admin>d:\python3.

6\learnpythonthehardway\第十五課.py d:\python3.

6\learnpythonthehardway\ex15.txt.txt

here's your file 'd:\\python3.6\\learnpythonthehardway\\ex15.txt.txt':

this is stuff i typed into a file

type the filename again:

> d:\python3.6\learnpythonthehardway\ex15.txt.txt

thisis stuff i typed into a file

第一次bai輸du入和第二次輸入都是需要輸zhi入路徑加dao.txt,這樣返回的結專果才是正確屬的。

12樓:l魯莊公

我也遇到了同樣的問題,網上也是搜不到答案,想了好幾種解決方案,終於版搞定了,首先權**是沒問題。主要是點用了argv這個執行指令,在windows 輸入時如果是變數的話看不出來差別的,但是如果輸入的是檔案的話必須得輸入全路徑,和書上那樣輸入的就會報錯。

希望採納,友情提示一下,python練習的檔案最後不要有中文路徑。

13樓:匿名使用者

no such file or directory: 'ex15_sample.txt'

這提示是沒找到檔案,確認一下檔案是否存在,另外看看路徑是不是有問題。

14樓:心月夕

把ex15_sample.txt放到和ex15.py同一個目錄下就沒問題了

15樓:虹__橋

應該是沒有寫出ex15_sample.txt的存放路徑。如果ex15_sample.txt和習題15.py存放路徑是一致的,那麼改內

成這樣試試:容python d:\python\----python\習題15.py d:\python\----python\ex15_sample.txt

笨辦法學python習題15報錯

c users admin d python3.6 learnpythonthehardway 第十五課.py d python3.6 learnpythonthehardway ex15.txt.txt here s your file d python3.6 learnpythonthehard...

有關Python匯入模組的問題,python中import匯入模組失敗的問題?

有關photo匯入模組的問題可以諮詢一下他這個作業系統 python中 import匯入模組失敗的問題?要看目錄的位置,是否和你這個指令碼在同一級目錄下,而且ping.py這個目錄裡也需要 init py這個檔案。如果解決了您的問題請採納!如果未解決請繼續追問 當多次import同一個模組時,只有第...

python多執行緒怎樣執行函式,pythonthreading模組,生成多執行緒之後,怎麼得到執行緒執行完成後return出的字串呢?

正常執行 但是執行緒執行狀態不受函式的控制 import threading threads 啟動多執行緒 if name main for t in threads t.setdaemon true t.start t.join 更多詳細操作help threading python thread...