国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

加拿大瑞爾森大學(xué) Python習(xí)題 Lab 4

2023-08-24 15:50 作者:逃跑的叮當(dāng)貓  | 我要投稿

Lab 4?– CPS?106

?

?

This lab helps you practice recursion, string manipulation and numerical approximation.

?

1. ??Assume that L is?a list?with?one?element.?The?element?might?be?a?number?or?it?might?be?a?list?of one?element,?where?that?element?might?be?a?number?or?a?list?of one?element,?and?so?on.?Return the innermost number. You must use recursion. Your solution cannot use a loop.

Hint: type(52) == int is True.

?

Test your program with?the following:

[5]

[[55]]

[[[123]]]

[[[[[[[[[[[[18]]]]]]]]]]]]

?

2. ??Assume?that?T?is?a?tuple.?Return?a?tuple?which?is?the?reverse?of T.?You?must?use?recursion.?Your solution cannot use a loop?or?a?list?or?a built-in?reverse?function.?Hint:?Reverse?the?tuple?starting?at?the?second?element,?and?concatenate?to?the?end?of?that?reversed?tuple?the?first?element.

?

Test your program with?the following:

(1,?2,?3,?4,?5)

('red', 'green',?'blue',?'yellow')

?

3. ??Assume?that ?sub?and?bigstring?are?strings.?Return?True?if?sub?is?part?of?bigstring,?False?otherwise.?You?must?use?recursion.?Your ?solution ?cannot ?use ?a ?string ?funtion ?or ?the ?'in?operation'. Your?solution?cannot use?a loop. Hint:?check?if?sub?is?the?beginning?of??bigstring,?and if?not, consider the string obtained by removing the first letter from?bigstring.

?

4. ??Assume?that?phrase?is?a?string.?Return?the?number?of words?in ?phrase.?Assume?that?words?are?separated?by?one?or?more?blanks.?You?are?not?allowed?to?use?the?built-in?function?split()?For?example,??countwords('The?cat?is?black')?would?return?4.?countwords('The?cat?is?black')?would also return 4. countwords('A whitecat?and a ??black cow.') would also return 7.

?

Test your program with?the following:

'A??white cat and ?a ?black cow'

'a b?c de?f?g?h'

"Orange you glad I didn't say banana"

?

5. ??Return the first value of?n such?that?the?sum

Sum?= 4/1 - 4/3?+ 4/5?-?4/7?+?...?+ 4?*?(-1)**(n+1)/(2n?-?1)

is?within?epsilon?of math.pi?=?3.141592653589793.?For?example,?if epsilon?is?1,?then?return?1,?since 4 is within?1 of?pi. If?epsilon is 0.5 then return?2,?since?4?is not?within?0.5?of?pi but?4?-?4/3?= 2.67, and that is within?0.5?of?pi



代碼:

4-2 tuple

4-3 findsub

4-3-2 findsub


加拿大瑞爾森大學(xué) Python習(xí)題 Lab 4的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
浦北县| 哈尔滨市| 汤原县| 清河县| 海口市| 桂平市| 长子县| 花莲市| 桐梓县| 石渠县| 延津县| 柳州市| 仪征市| 南安市| 抚州市| 耒阳市| 垣曲县| 广汉市| 靖安县| 三明市| 如东县| 闽清县| 巩义市| 前郭尔| 平乐县| 澄江县| 遂川县| 长宁区| 隆化县| 武陟县| 延长县| 南陵县| 漾濞| 湖口县| 石门县| 屯门区| 巢湖市| 河北区| 安达市| 泽库县| 海城市|