So my task is to ask users for names until they press control-d and then output in the format Adieu, adieu, to Liesl, Friedrich, and Louisa
where Liesl, Friedrich and Louisa are names input by the user. In my terminal, the results are correct no matter how many names I input, they output correctly, but check50 show a frown. Here's my code:
names = []
while True:
try:
#ask for input
name = input("Name: ")
#put in the list
names.append(name)
except (EOFError, ValueError):
print()
break
print("Adieu, adieu, to", end=" ")
#from first to second last, output names by comma
x = int(len(names)-2)
for amount in range(x):
print(names[amount] , "," , end=" ", sep="")
#use 'and' to output last name
names.reverse()
#if two names in list
try:
print(str(names[1]), end=" ")
print("and", str(names[0]))
#if one name in list
except (ValueError, EOFError, IndexError):
print(str(names[0]))
Use the check50 link to read the detailed error message, and/or re-read the instructions. Your solution doesn't match the expected output when there are 3 or more names.
Expected ouptut when there are 3 or more names:
Adieu, adieu, to Liesl, Friedrich, and Louisa
Adieu, adieu, to Liesl, Friedrich, Louisa, and Kurt
Your program outputs (compare commas):
Adieu, adieu, to Liesl, Friedrich and Louisa
Adieu, adieu, to Liesl, Friedrich, Louisa and Kurt
Also, did you read the Hint about the inflect
module? While not required, it will be very helpful in another pset.