我是新来的,这可能是一个非常愚蠢的问题,但我刚开始学习python并且在jupyter笔记本中遇到麻烦。例如:
def greatest(list):
biggest = 0
for i in list:
if e > biggest:
biggest = i
return biggest
然后我尝试:
print greatest([4,23,1])
错误消息显示语法错误:语句无效,同时指向“最大”区域之间的区域。和([4,23,1])在打印命令中。我一直试图打印类似的东西,总是有一个数字列表。我该怎么办?
答案 0 :(得分:0)
请参阅下面的代码。我纠正了一些事情,我已将其包含在代码注释中
def greatest(numbers): # Renamed list to numbers, since list is reserved
biggest = 0
for i in numbers:
if i > biggest: # e here should be i
biggest = i
return biggest
print(greatest([4,23,1])) # We need brackets around what we are printing since this is py3
答案 1 :(得分:0)