无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

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

加拿大瑞爾森大學 Python習題 Lab 5

2023-08-24 15:53 作者:逃跑的叮當貓  | 我要投稿

Lab 5??CPS?106

?

?

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

?

1. ??Find ?a??given??element??in??a??list??using??a??recursive??function.??The??function??is??defined??as?find(elm_list, x), where elm_list is the input list and x is the element to be?found. The?function?return the index of?x if?x is in the list, otherwise it returns -1.

?

Test you function with following:

[1.2,?3,?555,?66,?6,?35,?345,?345,?78,?12341],

x?=?78,

x?=?11

2. ??Write?a?function?that?computes?the?inner product?of two lists. The?inner product?of two?lists?L1 and L2 of?length n is defined?as?L1[0]?*?L2[0]?+?L1[1]?*?L2[1]?+?...?+?L1[n??1]?*?L2[n??1].?If?the lists are not of?the same length, the function should return None.

?

Test your function with the following:

L1?=?[8.17, 4.99,?16.56,?7.31,?0.21,?16.18,?13.75,?11.28, 4.3,?17.79]

L2?=?[17.68,?1.19,?2.64,?13.01,?8.5,?15.04,?0.3,?18.72, 4.58,?9.66]

?

3. ??Write?a?function?that?extract?a?number?from?a?string.?The?string?can?contain?any?character.?The?number?you?return?is?the?concatenation?of?all?the?digits?you?find?in?the?string.?For?example, the extracted number from the string “sk8dfjn*HG23Yh$%7-5~5”?is?823755.

?

Test your function with the following:

“1ksdj4sdf>R?387BDYGrrf%44@2”

?

4. ??Write a function that computes the?sum

1?+?1 /?2**2?+?1 / 3**2?+?...?+?1?/?n**2

for??a??given??integer??n.??For??large??n,??this??sum??converges??to??pi**2??/??6??where??pi??=?3.141592653589793. How large should n be for the sum to be?within?distance?0.001?of?pi**2?/?6?


代碼

5-1


5-2

5-3

5-4

5-4-2


加拿大瑞爾森大學 Python習題 Lab 5的評論 (共 條)

分享到微博請遵守國家法律
方城县| 鸡泽县| 四川省| 吴堡县| 维西| 滁州市| 宣化县| 那曲县| 铜川市| 通河县| 永仁县| 东兴市| 涪陵区| 巢湖市| 万安县| 昌乐县| 吴旗县| 仪陇县| 武平县| 阆中市| 蒙山县| 江津市| 神池县| 梁平县| 会泽县| 西宁市| 黄大仙区| 葫芦岛市| 万全县| 靖安县| 宾川县| 白河县| 兰州市| 鄂州市| 青州市| 独山县| 河源市| 扎赉特旗| 望城县| 龙江县| 古浪县|