Help with homework please- convert pseudocode to python

Please can someone help me with my homework. I need to convert the pseudocode below into python. Any help is gratefully received. Thanks

IF TimeOfMurder >= 6:00PM AND TimeOfMurder <= 8:00PM THEN
MissScarlett = “Innocent”
ProfessorPlum = “Innocent”
END IF

SELECT CASE LocationOfMurder:
CASE “1st Floor”:
ReverendGreen = “Innocent”
CASE “Ground Level”:
MissScarlett = “Innocent”
ColonelMustard = “Innocent”
CASE “Garden”
ProfessorPlum = “Innocent”

IF (MurderRoom == “Kitchen” OR MuderRoom == “Master Bedroom”) AND timeOfMurder >= 8:00PM THEN
ProfessorPlum = “Innocent”
ELIF MurderRoom == “Bathroom” AND (timeOfMurder >= 8:00PM AND timeOfMurder <= 8:30PM) THEN
MissScarlett = “Guilty”
END IF

IF MurderWeapon == “Candlestick” OR MurderWeapon == “Rope” THEN
MurdererGender = “Male”
END IF

Are you supposed to convert this into a function or are you supposed to be using objects? In either case, what is this supposed to return or how would you verify the result (the pseudocode did not say to print or return anything)? What inputs would you need for your function or class in order to do the calculation?

Do you know how to write an if statement? What about a switch case (using match and case)? If you can do those two things this should be pretty easy.

Thank you for your response. I am supposed to return the name of the murderer, but I dont believe I have enough information. I don’t know how to write an if statement or a switch case. Are you able to help please?
thank you

Just search for “python if statement” and “python match case” and you will find the documentation you need on those.

If you are supposed to return the name of the murderer, you would need those input variables. I am not certain it can be resolved for all possible inputs. I guess they want you to write a function. Personally I would use an object for each of the possible “suspects” which would include things like gender, is_guilty and such. If you do not know how classes work you can just use a simple list and use “suspect in maleSuspects” to eliminate the male suspects on that particular code path.

Other questions come up like: are the four explicitly named persons the only candidates?

1 Like

Thank you for your help. You have given me enough guidance to complete this task.