导航:首页 > 编程语言 > 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答案相关的资料

热点内容
成都市区建成面积算法 浏览:656
智能家居单片机 浏览:93
买男装用什么app好 浏览:851
文件夹合并了怎么拆开 浏览:256
波段副图源码无未来函数 浏览:84
livecn服务器地址 浏览:255
程序员这个工作真的很吃香吗 浏览:842
程序员和数学分析师待遇 浏览:676
压缩气弹簧怎么拆 浏览:319
华为公有云服务器添加虚拟ip 浏览:207
程序员和运营哪个累 浏览:22
抖音安卓信息提示音怎么设置 浏览:454
光速虚拟机的共享文件夹 浏览:246
程序员培训机构发的朋友圈真实性 浏览:742
天干地支简单算法 浏览:299
下载个压缩文件 浏览:298
普通人电脑关机vs程序员关机 浏览:628
米酷建站源码 浏览:115
氢气app怎么搜搭配 浏览:619
pdf绿盟 浏览:505