Question: Please use re module in python for every task even if there are other ways. 1: Define letters_only(s) which takes a string s and returns

Please use re module in python for every task even if there are other ways.

1: Define letters_only(s) which takes a string s and returns a boolean - whether it consists of letters only (both lower and upper case).

Example output: letters_only (" Hello ") Out [1]: True letters_only (" Hello !") Out [2]: False letters_only (" How are you ") Out [3]: False

2: Define count_syllables(s) which naively counts the number of syllables - takes a word s and returns an integer - the words number of vowels (aeiou).

Example output: count_syllables (" hello ") Out [1]: 2 count_syllables (" time ") Out [2]: 2 count_syllables (" task ") Out [3]: 1

3: Define get_id(s) which returns the first sequence of 3 consecutive digits of a string s. This will be useful for extracting the text id (XXX) from the filename atXXX YYYY(Y).txt (even though filename[2:5] would be much simpler). Assume that s always contains such a sequence.

Example output:

get_id (" at001_1234 . txt ") Out [1]: 001 get_id ("0987654321") Out [2]: 098 get_id ("01.01.2022") Out [3]: 202

Exercise:

import re

#Task1

def letters_only(s): """ Check whether a string consists of letters only (both lower and upper case), use re. :param s: any sequence of characters :rtype: bool """ # Task2 def count_syllables(s): """ Naively count the number of "syllables" = vowels (aeiou) in a word, use re. :param s: a sequence of lowercase letters :rtype: int """

# Task3 def get_id(s): """ Return the string of the first 3 digits of the filename, use re. :param s: any sequence of characters :rtype: str """

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!