162k views
4 votes
Create a list of 5 characters from your favorite game. Ask the user to enter their favorite character's name. If it is not present in the list tell the user that This character is not present in my list of favorites and ask the user whether they would like to add it. If the user says Yes, show them the list and ask at which position they would like to add it. Add the character's name at the respective position. If they would not like to add it then print Thank You for telling me your favorite character. If the name already exists then display a message saying Yay, one of our favorite character match.

this is a python question. So copy-paste your answer directly from the python app.
If you give me a good answer, you'll get 100 points :)

1 Answer

2 votes

Answer:

# List of favorite characters

favorite_characters = ['Mario', 'Link', 'Donkey Kong', 'Samus', 'Yoshi']

# Ask user to enter their favorite character

fav_character = input("Enter your favorite character: ")

# Check if character is present in list

if fav_character in favorite_characters:

print("Yay, one of our favorite characters match.")

else:

add_char = input("This character is not present in my list of favorites. Would you like to add it? (Yes/No): ")

if add_char.lower() == 'yes':

print(favorite_characters)

position = int(input("At which position would you like to add it? "))

favorite_characters.insert(position-1, fav_character)

print(f"{fav_character} added at position {position}.\\New list of favorite characters: {favorite_characters}")

else:

print("Thank you for telling me your favorite character.")

User Daniel Albert
by
8.5k points