Re: [闲聊] python小白问个问题

楼主: erimow (Erimo)   2024-08-06 11:14:48
Write a function called "findMin" which takes an list as input, and returns
the minimum element in the input list.
这题倒是对了
虽然不知道有没有可能会有意外情况
def findMin(list):
for i in list:
print(min(list))
return
print("undefined")
findMin([1, 2, 5, 6, 99, 4, 5]); # returns 1
findMin([]); # returns undefined
findMin([1, 6, 0, 33, 44, 88, -10]); # returns -10
昨天写的
Write a function called "table" which takes an input n, and prints out n x 1
to n x 9
def table(n):
for i in range(0, 10):
print(f"{n} x {i} = {n*i}")
table(3)
# 3 x 1 = 3
# 3 x 2 = 6
# ...
# 3 x 9 = 27
Write a function called "table9to9" that prints out the multiplication table:
def table9to9():
for i in range(1, 10):
for j in range(1, 10):
print(f"{i} x {j} ={i*j}")
table9to9();
# 1 x 1 = 1
# 1 x 2 = 2
# 1 x 3 = 3
# ...
# 1 x 9 = 9
# 2 x 1 = 2
# 2 x 2 = 4
# ...
# 9 x 9 = 81
作者: MurasakiSion (紫咲シオン)   2024-08-06 11:18:00
你第一题根本就不该for你会过是因为你return直接结束function你把for拿掉 缩排退回来结果完全一样==
作者: Wardyal (Wardyal)   2024-08-06 11:19:00
你丢第二三组测资会对吗
楼主: erimow (Erimo)   2024-08-06 11:19:00
是会对但我觉得怪怪的
作者: sustainer123 (caster)   2024-08-06 11:20:00
第一题直接min就结束了
作者: Wardyal (Wardyal)   2024-08-06 11:20:00
而且他说return element 你看起来像是print element
作者: MurasakiSion (紫咲シオン)   2024-08-06 11:20:00
你要把判断空不空移到最前面
作者: sustainer123 (caster)   2024-08-06 11:21:00
if list min(list) else returnundefined
作者: MurasakiSion (紫咲シオン)   2024-08-06 11:22:00
作者: sustainer123 (caster)   2024-08-06 11:24:00
就 print可以当作bug工具 正式提交通常会清掉
作者: Smallsh (Smallsh)   2024-08-06 11:29:00
剩我不会用pdb了

Links booklink

Contact Us: admin [ a t ] ucptt.com