Python從入門到精通第九章習題

2021-10-09 02:29:26 字數 1159 閱讀 5986

'''

遞迴呼叫,輸入的5個字元相反順序顯示

'''def

_91(

str, length)

:if length <0:

return

' 'else

:return

str[length]

+ _91(

str, length-1)

# str = input('請輸入5個字元:')

# length = len(str) - 1

# print(_91(str, length))

'''5個人坐一起,第5個人比第4個大2歲,第4個比第3個大2歲,···,第1個人10歲,第5個幾歲

'''def

_92():

age =

10for i in

range(1

,5):

age +=

2print

('第5個人%d歲'

% age)

# _92()

'''給乙個不多於5位數的正整數,求他是幾位數,逆序顯示各位數字

'''def

_93(num)

: length =

0 number =

str(num)

while num !=0:

length +=

1 num = num //

10print

(length, number[::

-1])

# a = int(input('請輸入小於5位的正整數:'))

# _93(a)

'''判斷5位數是不是回文數,並輸出全部回文數

'''def

_94():

for num in

range

(10000

,100000):

list

=str

(num)

iflist[0

]==list[4

]and

list[1

]==list[3

]:print

('{}是回文數'

.format

(list))

# _94()

python從入門到精通第九章(類)

import time from datetime import datetime d datetime.today 獲取當前日期時間 qingqi str d.isoweekday mingdan class home def init self,num,name self.num num sel...

關於Python程式設計 從入門到實踐第九章 「類」

對於初次學習python的小白使用這本書,在學習類的建立時候,會遇到方法init 的建立一直出問題 python類的建立class dog definit self,name,age self.name name self.age age def sit self print self.name.t...

Python程式設計 從入門到實踐第九章練習9 4

先對各類被匯入檔案進行類的分配 class restaurant def init self,restaurant name,cuisine type 初始化屬性 self.restaurant name restaurant name self.cuisine type cuisine type ...