Ask Question
7 July, 18:54

Write the function lettersOnly (s) that takes in a string called s, and returns a string containing only the alphabetic characters of s.

+5
Answers (1)
  1. 7 July, 19:51
    0
    The program to this question as follows:

    Program:

    def lettersOnly (s) : #defining method lettersOnly

    val="" #defining string variable that return value

    for i in s: #defining loop to calculate value

    if (i. isalpha ()) : #check condition that value is string

    val=val + i #add value

    return val #return value

    print (lettersOnly ("data3base_ro1c3k5s")) #call method and print value

    Output:

    databaserocks

    Explanation:

    In the above python code, a method lettersOnly is declared that accepts a string variable "s" in its parameter. Inside the method, a string variable "val", and loop is declared, in which the "val" variable holds method return value.

    In the loop and if block is used that uses "isalpha" string method, which checks the check alphabetic character in the given value. if this is true it will calculate all value in "val" variable and return its value. At the last, the print method is used, which calls the lettersOnly method and prints its return value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the function lettersOnly (s) that takes in a string called s, and returns a string containing only the alphabetic characters of s. ...” 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