206k views
5 votes
Write a function named spell_name that takes in a string name as parameter, and returns a list where each character in the name is an item in the list. In your main program, call this function and print the returned list.

For example:
spell_name("Jessica") should return ['J', 'e', 's', 's', 'i', 'c', 'a']


Be sure to:
include comments for all functions that you create.
validate any user inputs using try-except-else-finally and/or if-else.
validate all parameters passed to functions you write using try-except-else-finally and/or if-else.
(30 points)

User Aswathy S
by
7.7k points

1 Answer

5 votes
def spell_name(name):
"""
Takes in a string name as parameter, and returns a list where each character in the name is an item in the list.
"""
# Create an empty list to store the characters of the name
name_list = []

# Iterate over each character in the name and append it to the list
for char in name:
name_list.append(char)

# Return the list of characters
return name_list

# Ask the user for input
name = input("Please enter a name: ")

# Call the spell_name function and print the returned list
try:
name_list = spell_name(name)
print(name_list)
except:
print("Error: invalid input")
User Mcritz
by
8.1k points