Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem # 2 : Volunteer Shifts You are volunteering for an event, and the event coordinator has divided all volunteers into shifts, which are all

Problem #2: Volunteer Shifts
You are volunteering for an event, and the event coordinator has divided all volunteers into shifts, which are all numbered. The event coordinator has organized all of this using a simulated "spreadsheet", which is a string formatted like so:
[Volunteer Name 1]: Shift [Shift #]
[Volunteer Name 2]: Shift [Shift #]
The square bracket notation means that a particular string or number will be substituted there. Each shift number is either a one-digit or two-digit number. The In notation represents the newline character. We are using it to separate parts of the string from each other. Even though it consists of I and n, it's actually considered a single character!
Complete the function find_volunteer_shift(volunteer_name, spreadsheet), which reads in a volunteer's name, and returns the volunteer's corresponding shift, which should be an integer value (Hint: use the int() function.) You may assume that a volunteer is only listed once in the spreadsheet string, and that they are assigned only to one shift.
If the volunteer name doesn't exist in spreadsheet, return -1.
Example #1:
find_volunteer_shift('Tina', 'Daniel: Shift 12 InJane: Shift 1 InTina: Shift 10?? In
George: Shift 2inJoe: Shift 3inStella: Shift 3ln')
Return value: 10
Example #2:
find_volunteer_shift('Stella', 'Daniel: Shift 12InJane: Shift 1 InTina: Shift 10In
Return value: 3
Example #3:
find_volunteer_shift('Adam', 'Daniel: Shift 12lnJane: Shift 1lnTina: Shift 10
George: Shift 2lnJoe: Shift 3inStella: Shift 3ln')
Return value: -1
Example #4: George: Shift 2lnJoe: Shift 3ln Stella: Shift 3lnBob: Shift 6ln Kathy: Shift
image text in transcribed

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

Students also viewed these Databases questions