python: def shakespeare_position(role, section):     """

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

python:

def shakespeare_position(role, section):
    """
    Question 2 - Regex

    You are reading a Shakespeare play with your friends (as one frequently does) and are given a role.
    You want to know what line immediately precedes YOUR first line in a given section so that you are ready to go
    when it is your turn. Return this line as a string, excluding the character's name.

    Lines will always begin with the character's name followed by a ':' and end in a "." or a "?"
    Each line is separated by a single space.

    THIS MUST BE DONE IN ONE LINE.

    ""

    Args:
    role (str)
    section (str)

    Returns:
    str

    section_1 = 'Benvolio: By my head, here come the Capulets. Mercutio: By my heel, I care not. ' +
    'Tybalt: Gentlemen, good den - a word with one of you. Mercutio: And but one word with one of us?'

    >>> shakespeare_position('Tybalt', section_1)
    'By my heel, I care not.'
    >>> shakespeare_position('Mercutio', section_1)
    'By my head, here come the Capulets.'

    """

# section_1 = 'Benvolio: By my head, here come the Capulets. Mercutio: By my heel, I care not. ' + \
    # 'Tybalt: Gentlemen, good den: a word with one of you. Mercutio: And but one word with one of us?'
    # pprint(shakespeare_position('Tybalt', section_1))
    # pprint(shakespeare_position('Mercutio', section_1))

Expert Solution
Step 1

Program to solve above problem using Python.

Let us Assume character name is followed by :

and Each line is end with '.'

Let us consider the section of Shakespeare playlet

Section: 'Benvolio: By my head, here come the Capulets. Mercutio: By my heel, I care not. ' +
'Tybalt: Gentlemen, good den - a word with one of you. Mercutio: And but one word with one of us?'

Roles: are Benvolio, Mercutio, Tybalt

                                   First line by Benvolio : By my head, here come the Capulets. 

                                   Second line by Mercutio: By my heel, I care not.

                                   Third line by Tybalt: Gentlemen, good den - a word with one of you.

                                   Fourth line by Mercutio: And but one word with one of us?

We give Section and Roles are input to the function shakespeare_position()

You want to know what line immediately precedes, so that given role should get ready for his dialogue. 

 

 

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

could you do it in one line of code and using regex please

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY