So I am trying to better understand functions and using for loops to select from multiple lists. Here is the basic function that I created and it does work:
def my_function(person, feeling):
print('Hello, %s, how are you? It seems that you are feeling %s!' %(person, feeling))
my_function('Matthew', 'rejuvinated')
But to take this further, I would like to pick a name and a feeling from their respective lists and insert them into the new function. When I try the following, I get an error. Any help would be greatly appreciated!
people = ['Colby', 'Hattie', 'Matthew', 'Stephen', 'Lee', 'Deb', 'Sharon', 'Pete']
feelings = ['happy', 'sad', 'cold', 'cranky', 'happy', 'successful', 'spunky', 'warm', 'nerdy']
def my_function(person, feeling):
"""This function produces a statement which inserts a name and a feeling"""
for p in enumerate(people):
person = p
for f in enumerate(feelings):
feeling = f
print('Hello, %s, how are you? It seems that you are feeling %s!' %(person, feeling))
return my_function()
my_function(people, feelings)
Hello, (7, 'Pete'), how are you? It seems that you are feeling (8, 'nerdy')!
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-2b2a265c427c> in <module>
11 return my_function()
12
---> 13 my_function(people, feelings)
<ipython-input-1-2b2a265c427c> in my_function(person, feeling)
9 feeling = f
10 print('Hello, %s, how are you? It seems that you are feeling %s!' %(person, feeling))
---> 11 return my_function()
12
13 my_function(people, feelings)
TypeError: my_function() missing 2 required positional arguments: 'person' and 'feeling'
return my_function()your function accept two argument, but you are calling with no arguementenumerate?peopleand one feeling from the secondfeelings, produce the sentenceHello Matthew, how are you? It seems that you are feeling nerdy!. I figuredenumeratewas the way to go but I guess not?enumerate(people)returns?