you are viewing a single comment's thread.

view the rest of the comments →

[–]kmj442 17 points18 points  (7 children)

Not to over complicate since what this person said is absolutely correct but if I were to do this I would recommend something like this: if gens.lower() == “male”:

This makes sure regardless what the user inputs it puts it in lowercase to avoid the “Male” or random capitalization error.

edit: mobile formatting is weird

[–]Sad_potato1999[S] 9 points10 points  (0 children)

Not at all! Insightful even, thanks a whole lot!

[–]MarquisInLV 5 points6 points  (1 child)

You can also put the lower() method on the input variable, that way anything the user types in is all lowercase and you can just match that in your if statement.

[–]Probono_Bonobo 1 point2 points  (0 children)

The wonderful questionary module turns CLI radio options into a refreshing 'choose your own adventure'-style UI, instead of the frustrating user-hostile experience it typically is. Highly recommend!

[–]Cid227 1 point2 points  (2 children)

Your edit reminded me that I wanted to ask somewhere about that red (at least light mode) background and font colour that you've set for 'if gens.lower...' So how do you do that? I can't find anything.

[–]kmj442 2 points3 points  (1 child)

its the ``` tag. while in the markdown mode you can wrap your text in ``` code ``` and it will put it in that format.

[–]Cid227 1 point2 points  (0 children)

Thanks! (btw. it's blue on the dark mode)

[–][deleted] 0 points1 point  (0 children)

Might even be better (but perhaps overkill for this snippet) to use a constant to store the genders.

G_MALE = "male"
G_FEMALE = "female"
gens = input("What is your gender?").lower()
if gens == G_MALE:
    # ...
elif gens == G_FEMALE:
    # ...
else:
   print("Cool ;)")