+ 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.
3 Respuestas
+ 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".
+ 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.
+ 2
Thank you Hatsy Rei, I never knew about that!