In: Computer Science
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.
Colour |
Message |
Blue |
“No virus” |
Yellow |
“Needs to be under observation” |
Red |
“Needs to be admitted in COVID ward” |
def blue_color():
return "Observing blue color means: No virus"
def yellow_color():
return "Observing yellow color means: Needs to be under observation"
def red_color():
return "Observing red color means:Needs to be admitted in COVID ward"
def default():
return "No observation:empty"
switcher = {
1: blue_color,
2: red_color,
3: yellow_color
}
def switch(observation):
return switcher.get(observation, default)()
print(switch(1))
print(switch(2))
print(switch(0))