0

I had the code working when you could only put in the gender with a capital but I added more to allow the user to input their gender with a lower case to make it more user friendly. I was doing research to be able to have both "Male" and "male" to be assigned to the same variable "M" and the same for female but I could not figure it out. I decided to assign each word with its own variable and then ask the if statement to be true if either variable was called from user input. Now when I have this, both if statements come out true and print their message no matter the circumstance. The code is written in python on Replit. This is the code:

gender = input("Please state your gender: ")

M = 'Male'
F = 'Female'
m = 'male'
f = 'female'

if gender == M or m:
  print("You are a male")

if gender == F or f:
  print("You are a female")
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Josh
  • 1
  • `if gender == M or m:` --> `if gender == M or gender == m:` – balderman Nov 19 '21 at 15:00
  • 2
    You could just do `input().lower()` and only check one value, assuming you're okay with entering `MaLe` – OneCricketeer Nov 19 '21 at 15:01
  • See also: [How do I do a case-insensitive string comparison?](https://stackoverflow.com/q/319426/10077) – Fred Larson Nov 19 '21 at 15:01
  • when you say `if gender == M or m: ` python interprets that as `if (gender == M) or m: ` so this isn't what you are looking for. You have to say `or gender == m` like @balderman noted – troy Nov 19 '21 at 15:01

0 Answers0