First we'll need to read the user's input after they read the question:
hungry = input("Are you hungry? True or False \n")
Now that we have their response in a variable, hungry
, we're able to use it in some statements:
if hungry.lower() == "true":
Notice the use of .lower()
, which will take their string, regardless of capitalisation of letters, and convert it all to lowercase. This means that whether they enter "True"
, "tRue"
or "TRUE"
, they will all evaluate to being True
if compared to the lowercase counterpart "true"
.
What's important when doing this, is to always have your comparison string be lowercase as well. because if you tried evaluating "true"
against "True"
, it would return False
.
Using this knowledge, we're able to put it all together and print out what we want:
hungry = input("Are you hungry? True or false \n")
if hungry.lower() == "true":
print("Feed me!")
else:
print("I'm not hungry.")