導航:首頁 > 編程語言 > thinkpython答案

thinkpython答案

發布時間:2022-06-29 03:44:05

㈠ 用python如何得到以下答案

#定義一個查找字元的函數
deffint(st1,st2):
chang1=len(st1)
changzong=len(st2)
print(st1,"在"+st2+"中出現的次數是:",st2.count(st1),"次")
ifst2.find(st1)>=0:
wei=[]
foriinrange(0,len(st2)):
new=st2[i:i+len(st1)]
ifnew==st1:
wei.append(i+1)
print(st1,"出現的位置是:",wei)
else:
print(st1,"不在字元串",st2,"中")
#測試這個函數是否有效
sss="hdbdhdbdbjssveoehow"
s1="bd"
fint(s1,sss)
#只需要將變數s1和sss給與不同的值就會測試不同的字元串

㈡ Python編程提問

代碼邏輯是沒啥問題的,格式方面有點問題。可能Tab鍵和空格鍵混用,或者空格鍵沒有統一。

但是有一個問題,既然是猜數,為啥答案是輸入的,次數是輸入的,猜的也是輸入的。那游戲有啥意思?

原先寫過一個類似的,如有興趣,可做參考:

defisEqual(num1,num2):
ifnum1<num2:
print'TooSmall'
returnFalse;
elifnum1>num2:
print'TooBig'
returnFalse;
else:
print'bingo'
returnTrue;

fromrandomimportrandint
num=randint(1,101)
print'GuesswhatIthink?'
bingo=False
whilebingo==False:
answer=input()
bingo=isEqual(answer,num)

㈢ python 編程 求答案!2、3兩題

#!/usr/bin/envpython
#coding=utf-8
importre
,timedelta
importplatform

ifplatform.python_version()[:1]=='2':#判斷python版本是2還是3
importsys
reload(sys)
sys.setdefaultencoding('utf8')

classIdcard(object):
'''
>>>m=Idcard('225122198611134730')
>>>print(m.sex)

>>>m.birth
'1986-11-13'
>>>m.age
30
'''
def__init__(self,idcard):
self.idcard=idcard
iflen(idcard)==15:
sex,birth=idcard[-1:],'19'+idcard[6:12]
eliflen(idcard)==18:
sex,birth=idcard[-2:-1],idcard[6:14]
else:
raiseException('len(idcard)is{}(15/18)'.format(len(idcard)))
self._sex=int(sex)%2
self._birth=birth

@property
defsex(self):
returnu'男'ifself._sex%2elseu'女'

@property
defage(self):
now,bir=dt.now(),dt.strptime(self._birth,'%Y%m%d')
beforebirth=(now-dt(now.year,bir.month,bir.day)).days<0
returndt.now().year-int(self._birth[:4])-beforebirth

@property
defbirth(self):
returndt.strptime(self._birth,'%Y%m%d').strftime('%Y-%m-%d')

defalignment(str1,space,align='left'):
length=len(str1.encode('gb2312'))
space=space-lengthifspace>=lengthelse0
ifalign=='left':
str1=str1+''*space
elifalign=='right':
str1=''*space+str1
elifalign=='center':
str1=''*(space//2)+str1+''*(space-space//2)
returnstr1

defmain():
fname='customer.txt'
'''
withopen(fname,'w')asf:
f.write("""
鄭文傑225122198611134730
文萍225122198912094740
鄭媽媽225122590303476
鄭爸爸225122560506471
""")
'''
newf='ourcustomers.txt'
withopen(fname)asf:
s=f.readlines()
L,newL=[re.split(r's+',i.strip())foriins],[]
foriinL:
iflen(i)==2:
g=Idcard(i[1])
newL.append('{}{}{}'.format(
alignment(i[0],10),alignment(g.sex,8),g.age))
withopen(newf,'w')asf:
f.write(' '.join(newL))
print(' '.join(newL[:100]))
print('Customerdatahasbeenwriteinto{}'.format(newf))

if__name__=='__main__':
importdoctest
doctest.testmod()
main()

㈣ python, 誰有Think Python: How to Think Like a Computer Scientist。。。 這本書的中文版啊!!

恐怕你得失望了,Python的書很多沒有中文版,除了出版社,社區的人可能會熱心翻譯下,最壞的情況是你得自己啃E文

㈤ Python求解答過程

第11題

因為取字元串TempStr的從TempStr[3]到TempStr[-2]的字元,

這里的下標都是從0開始,Python的數學取值區間都是[3,-1)半開區間,

因此取值范圍是[3,-2],運行結果是3.14159

㈥ 頭歌python的答案在哪裡找

CSDN上找。
進入公眾號主頁,點擊右上角搜索按鈕,輸入作業題目關鍵字,獲取答案。CSDN是功能齊全,大部分題目都可以搜到。
Python提供了高效的高級數據結構,還能簡單有效地面向對象編程。Python語法和動態類型,以及解釋型語言的本質,使它成為多數平台上寫腳本和快速開發應用的編程語言,隨著版本的不斷更新和語言新功能的添加,逐漸被用於獨立的、大型項目的開發。

閱讀全文

與thinkpython答案相關的資料

熱點內容
滴滴號碼加密怎麼解除 瀏覽:844
模具編程的職責 瀏覽:941
華為ssh改加密演算法 瀏覽:147
文件夾空白合同 瀏覽:761
pythonwebpy開發 瀏覽:669
不是c編譯器的有 瀏覽:660
win10壓縮包下載 瀏覽:905
逆戰手機app怎麼樣 瀏覽:946
自嗨自我解壓圖片 瀏覽:395
電子書導入kindle哪個文件夾 瀏覽:418
pythontcpserver性能 瀏覽:544
linux文件夾改名 瀏覽:564
單片機開發板是什麼 瀏覽:851
阿里雲伺服器不能截屏 瀏覽:866
如何自己製作聯想伺服器 瀏覽:843
停車場規劃演算法 瀏覽:923
深蹲PDF 瀏覽:908
數據科學包python 瀏覽:849
程序員學習視頻網站 瀏覽:126
吃雞游戲如何安卓轉蘋果 瀏覽:188