Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

Consider this article:...

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago