I am encountering a problem for an assignment in my python3 class.
The code runs how is supposed to.
Ask the user the names of their dogs until they type ‘DONE’ and then tell them that each of their dogs are awesome by name.
However when I run the program you have to go through the input twice before you can get an output. I am new to this so I am sure the fix is quite simple.
Here is what I have:
def main():
doggo_names = get_doggo_names()
output_names(doggo_names)
def get_doggo_names():
name = ''
names = []
while name != 'DONE':
name = input('Name of doggo: ')
if name != 'DONE':
names.append(name)
return names
def output_names(doggo_names):
print()
for names in get_doggo_names():
print(names + ' ', end='is awesome.\n')
main()
>Solution :
Your code should be like this:
def main():
output_names()
def get_doggo_names():
name = ''
names = []
while name != 'DONE':
name = input('Name of doggo: ')
if name != 'DONE':
names.append(name)
return names
def output_names():
for names in get_doggo_names():
print(names + ' ', end='is awesome.\n')
main()