def
您忘记在and之后缩进行for
:
mylist=input('Who is visiting today?')
def GoodDaySir():
for i in range(len(mylist)):
print('Hello to you.')
print('Have a good day, ', mylist)
虽然我不知道你想用这段代码完成什么;-)
你可能想要这样的东西:
def GoodDaySir(visitors):
""" This function takes a list() of visitors and prints out a greeting
for each person.
"""
for person in visitors :
print('Hello to you.')
print('Have a good day, ', person)
# Get a list of names separated by ","
visitors = raw_input('Who is visiting today?')
# Convert the string to an actual list()
visitorsList = [x.strip() for x in visitors.split(',')]
# Call our function with the list as parameter and greet the visitors
GoodDaySir(visitorsList)