I am stuck with my code on my assestment. I have passed with sufficient score but I dont like to leave any question on fail- for my own learning. I manaed to get all statements, apart from the last one, where if first and last name are black, the output should be empty. But I am still getting Name - this word shoul dnot be there at all.
Thanks a lot!
# code goes here
if len(first_name)==0:
string="Name: "+last_name
elif len(last_name)==0:
string="Name: "+first_name
elif len(last_name)==0 and len(first_name)==0:
string=""
else:
string="Name: "+last_name+", "+first_name
return string
print(format_name("Ernest", "Hemingway"))
# Should return the string "Name: Hemingway, Ernest"
print(format_name("", "Madonna"))
# Should return the string "Name: Madonna"
print(format_name("Voltaire", ""))
# Should return the string "Name: Voltaire"
print(format_name("", ""))
# Should return an empty string
Name: Hemingway, Ernest
Name: Madonna
Name: Voltaire
Name:
Aucun commentaire:
Enregistrer un commentaire