Home > Blockchain >  How can i have 2 input if statements?
How can i have 2 input if statements?

Time:10-10

i want it so if is_male == "Y": and if is_male == "N": also works when they you type y and n (with no capslocks)

name = input("Enter your name: ")
age = input("Enter your age: ")
is_male = input("Are you a man? Y/N: ")
if is_male == "Y":
    print("Your name is "   name   " you are "   age   " years old and you are a male.")
if is_male == "N":
    print("Your name is "   name   " you are "   age   " years old and you are a female.")

CodePudding user response:

if is_male.lower() == "y":
    ...

if is_male.lower() == 'n':
    ...

This will make it case insensitive so it works for both Y and y.

CodePudding user response:

You can change like this.

if is_male == "Y": -> if is_male == "Y" or is_male == "y":

if is_male == "N": -> if is_male == "N" or is_male == "n":

CodePudding user response:

Why not make is_male a bool? The value would fit it's variable name more appropriately. You can do that when you ask for input:

is_male = input("Are you a man? Y/N: ").upper() == 'Y'

Then your if statement would be:

if is_male:
    ...
else:
    ...
  • Related