Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

brought_food = true brought_drink = false # these lines dont work! fix …

Question

brought_food = true
brought_drink = false

these lines dont work! fix them so that they do.

print(\did the person bring food? \ + brought_food)
print(\did the person bring a drink? \ + brought_drink)
booleans, like integers, have to be converted to strings before they can be added to strings. see if you can fix this program, which should print whether or not someone brought food to a party and whether or not they brought a drink.

Explanation:

Step1: Convert boolean to string

In Python, when you want to concatenate a boolean value (True or False) with a string, you need to convert the boolean to a string. You can use the str() function for this.
For the first print statement:

print("Did the person bring food? " + str(brought_food))

Step2: Convert boolean to string

For the second print statement:

print("Did the person bring a drink? " + str(brought_drink))

Answer:

The corrected code is:

brought_food = True
brought_drink = False

print("Did the person bring food? " + str(brought_food))
print("Did the person bring a drink? " + str(brought_drink))