Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

weird / confusing ones to watch out for: bool(n) => true (non - empty s…

Question

weird / confusing ones to watch out for: bool(n) => true (non - empty string) bool(false) => true (non - empty string) bool(0,0) => true (non - empty list) task 1. first input: · 1a. ask are you hungry? (y or leave blank) · 1b. convert the input to a boolean (true / false) 2. second input · 2a. ask do you have food? (y or leave blank) · 2b. convert the input to a boolean (true / false) 3. use if/elif/else to select one of 4 possible outputs: · 3a. if hungry and have_food: output make dinner · 3b. elif hungry: (have_food must be false otherwise wed never have got this far) output eat out · 3c. elif have_food: (hungry must be false) output watch tv · 3d. else: (both must be false) output go shopping remember: an elif condition will only be checked if all the if & elif conditions before it have already failed (ie returned false ), so you only need to check one condition in each elif (and you dont need to check any conditions in the else, because the only possibility left should be false false )

Explanation:

Step1: Take first input

Ask user "Are you hungry? (Y or leave blank)". If user enters 'Y', consider it as True (non - empty string implies True), if leaves blank consider as False.

Step2: Convert first input to boolean

If input is 'Y', boolean value is True, else False.

Step3: Take second input

Ask user "Do you have food? (Y or leave blank)". If user enters 'Y', consider it as True (non - empty string implies True), if leaves blank consider as False.

Step4: Convert second input to boolean

If input is 'Y', boolean value is True, else False.

Step5: Use if/elif/else

If both hungry (first boolean) and have_food (second boolean) are True, output 'Make dinner'. If hungry is True and have_food is False, output 'Eat out'. If have_food is True and hungry is False, output 'Watch TV'. If both are False, output 'Go shopping'.

Answer:

Follow the above steps to get the appropriate output based on user inputs.