Week-05 Assessment: Sample Questions

[ Question 1 ] [ Question 2 ]


Question 1

You have two sensor readings which are stored in two Python variables x and y of float type.

The table below shows the value of output_string for different values of x and y.

x <= 50 x > 50
y < 100 normal normal
y >= 100 alert poor-performance

The following Python code segment should determines a Python variable output_string (of string type), based on the values of x and y.

Please fill the blanks below, and importantly briefly justify your answers to you tutor.

if _____1_____:
    output_string = 'normal'
else:
    if _____2_____:
        output_string = 'poor-performance'
    else:
        output_string = _____3_____


Answers (also provide brief justifications):

1) y < 100 
2) x > 50 
3) 'alert'