【发布时间】:2016-05-22 04:17:41
【问题描述】:
我正在练习 Python - 使用 Python 3.5.0 - 我遇到了这个使用子程序的简短程序。我想弄清楚每个子程序的作用是什么?
非常感谢您。
def A(target,mark)
target=mark[0]
for numbers in range(10):
if mark[numbers] > target:
target = mark[numbers]
return target
def B (target, mark)
target=mark[0]
for numbers in range(10):
if mark[numbers] < target:
target = mark[numbers]
return target
def C (vote,total,vote1,vote0)
for noofvotes in range(total):
if vote[noofvotes]==1:
vote1=vote1 + 1
else:
vote0=vote0 + 1
return vote0, vote1
def D(target,Name):
found="NO"
namesinarray=0
while namesinarray != len(Name) and found == "NO":
if Name[namesinarray]==target:
found="YES"
indexmark= namesinarray
namesinarray = namesinarray +1
if found=="YES":
print(target + " has been found at position " + str(indexmark))
else:
print("This name is not in the list")
【问题讨论】:
-
不知道谁写了这段代码,但太可怕了。话虽如此,您仍然应该能够自己找出每个功能的作用。提示:如果仅仅阅读和推理代码还不够,Python 有一个交互式解释器和一个步进调试器(您可以从交互式解释器启动)。
标签: python python-3.x for-loop python-3.5