Ask Question
17 October, 23:25

Write a function called name_facts that will take a firstname (string) as an input parameter, and print out various facts about the name, including:

1) its length, 2) whether it starts with the letter A, and 3) whether it contains a Z or X.

To gain full credit for this exercise, you must use string formatting to print out the result. Hints: You will probably want to convert the string to lowercase when checking conditions 2 and 3. You can get by without it, but you'll have to make sure you check both lower and uppercase versions of the letters. You will have to use the in operator for condition 3. You will also probably want to make a separate message for conditions 2 and 3 (depending on the answer) and use string formatting to join them into the final message.

+3
Answers (1)
  1. 18 October, 00:21
    0
    def name_facts (firstname):

    print ("Your name is", len (firstname),"letters long", end=", ")

    if (firstname[0] = = 'A'):

    print ("does start with the letter A", end=", ")

    else:

    print ("does not start with the letter A", end=", ")

    if (firstname. count ('Z') >0 or firstname. count ('X') >0):

    print ("and does not contain a Z or X")

    else:

    print ("and does not contain a Z or X")

    #Testing

    name_facts ("Allegra")

    name_facts ("Xander")
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function called name_facts that will take a firstname (string) as an input parameter, and print out various facts about the name, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers