mardi 25 septembre 2018

How to ask for a boolean input from a user to qualify if statements and print a sentence using that information in Python

I'm here with my first (hopefully not last) query for you.

I'm trying to get information from the user, specifically boolean values to determine if they are male/female and tall/short, then print the correct statement of "You are a tall/short male/female"

is_tall = input("Are you tall?")
is_male = input("Are you male?")

if is_tall and is_male:
  print("You are a tall male")
elif is_tall and not(is_male):
  print("You are a tall female")
elif not(is_tall) and is_male:
  print("You are a short male, sorry")
else:
  print("You are a short female, sorry")

My code runs and always returns "You are a tall male", searching reveals this is because the users input is considered always true as it is a string.

I've seen other examples for grabbing boolean values but not for grabbing two and using them both within if statements. Am I anywhere close here, what am I missing? I know I can't use bool() around the input to convert it.

Aucun commentaire:

Enregistrer un commentaire