【发布时间】:2020-12-11 17:30:06
【问题描述】:
def myNames():
names = []
while True:
a = input("Enter Name: ")
if a != "done":
names.append(a)
elif a == "done":
return names
def all_lengths(myNames):
num_of_strings = len(myNames)
total_size = 0
for item in myNames:
total_size += len(item)
ave_size = float(total_size) / float(num_of_strings)
print(ave_size)
all_lengths(myNames())
def longestWord(myNames):
count = 0
for i in myNames:
if len(i) > count:
count = len(i)
word = I
print ("the longest string is ", word)
我怎样才能让它打印出用户输入的最长的名字,例如:在 Samantha 和 John 中,它会说 Samantha 是最长的名字。我需要它来计算最长的名字并从第一个函数中显示出来,而不会让我再次输入名字
【问题讨论】: