Why is this happening (Python)??????? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Why is this happening (Python)???????

So im currently making a simulator similar to LifeGame (https://code.sololearn.com/c3ZG1lFhdN3z/#py) But instead it is with animals. Here is the link: https://code.sololearn.com/c4zs050Tq0ih/#py As you can see, at the bottom of the code there is a function that outputs a random message depending upon the gender. I printed that with the gender above, but it always outputs the male messages, even when it is female. How do I go about getting it to show one of the female messages when the gender is female, and vice versa? Thanks.

10th Nov 2018, 3:47 AM
DrChicken24
DrChicken24 - avatar
3 Answers
+ 9
gender == "male" or "Male" is evaluated as (gender == "male") or ("Male") in which "Male" as a string is always true. Same goes for the condition check for female. Instead, do gender == "male" or gender == "Male" or even better, just downcase gender and compare it with "male" or "female".
10th Nov 2018, 4:01 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Hatsy Rei Sorry lol I have another question: I added a second function to the code choosing the home of the user. In the function I defined the variable home, yet a NameError outputs and it says home isnt defined. Maybe it is something im overlooking but I cant figure it out! Edit: Nevermind, I figured it out.
10th Nov 2018, 5:06 AM
DrChicken24
DrChicken24 - avatar
+ 2
Thank you Hatsy Rei, I never knew about that!
10th Nov 2018, 4:12 AM
DrChicken24
DrChicken24 - avatar