Point me everything i did wrong?! [Simple PYTHON Code] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Point me everything i did wrong?! [Simple PYTHON Code]

would you guys point and explain me everything i did wrong. Here is my code https://code.sololearn.com/c91asIXDi8vX/?ref=app

22nd Mar 2020, 11:27 AM
DarkPrince
DarkPrince - avatar
13 Answers
+ 1
Syed Kabir change ur conditions a little bit. if p.lower() == "boy" elif p.lower() == "girl" Now what is does is that whatever he inputs like GIRL, it would turn into lower caps, and you would not have to worry about Girl, girl and GIRL. otherwise, if u wanna stick to ur code, then, dont do it like this: if p == "girl" or "Girl" or "GIRL": but do it like this: if p == "girl" or p == "Girl" or p == "GIRL"
22nd Mar 2020, 5:19 PM
maf
maf - avatar
+ 2
1. Your "else" statement has a space before it. Python interprets and understands code using indents. Because of the space, python doesn't know how to interpret it. So remove the space. 2. Change [Boy, boy] to "Boy" or "boy" and the same with "Girl"
22nd Mar 2020, 11:48 AM
Taranjeet
Taranjeet - avatar
+ 2
Syed Kabir p = input("Are you Girl or Boy?\n") q = int(input("What\'s your AGE?\n")) r = input("What\'s your Name?\n") if p == "boy" or "Boy" and q >= 22 : print(r, "! ", "What\'s up Bruv ?", sep=" ") elif p == "Girl" or "girl" and q >= 18 : print("Hey Beautiful!\n") else : print("Goodbye!!\n") Now it should work, what i did was that I put quotation marks around Boy, boy, Girl and girl as they were strings.
22nd Mar 2020, 12:08 PM
maf
maf - avatar
+ 2
Syed Kabir I added double quotes for that. As you have not did that, Python thinks that boy is a variable, that's why.
22nd Mar 2020, 12:32 PM
Taranjeet
Taranjeet - avatar
+ 2
p = input("Are you Girl or Boy?\n") q = int(input("What\'s your AGE?\n")) r = input("What\'s your Name?\n") if p == "boy" or "Boy" and q >= 22 : print(r, "!", "What\'s up Bruv ?", sep=" ") elif p == "Girl" or "girl" and q >= 18 : print("Hey Beautiful!\n") else : print("Goodbye!!\n")
22nd Mar 2020, 2:11 PM
Justus
Justus - avatar
+ 2
Strings should have " "
22nd Mar 2020, 2:12 PM
Justus
Justus - avatar
+ 1
Tnx Taranjeet . Didn't work Error: Nameerror: boy is not defined
22nd Mar 2020, 11:57 AM
DarkPrince
DarkPrince - avatar
+ 1
Tnx maf. it worked perfectly now. Would you please explain again more elaborately.
23rd Mar 2020, 3:27 AM
DarkPrince
DarkPrince - avatar
+ 1
What was actually caused that problem earlier : {Input p > Girl Input q > 19 Input r > tina Output -> tina ! What's up Bruv ?} p == "boy" or "Boy" # I think, it was the reason for this problem. But why?
23rd Mar 2020, 3:48 AM
DarkPrince
DarkPrince - avatar
+ 1
Syed Kabir from what i learned, you can't have condtions like this, if greet == "hello" or "hi" What is after or? It is not a part of greet, if greet == "hello" or greet == "hi": so mention greet again, compare both. the problem was only this, you didnt mention p again and again, WRONG: p == something or otherthing or somethingelse. CORRECT: p == something or p == otherthing or p == somethingelse so u have to mention p again and again.
23rd Mar 2020, 6:09 AM
maf
maf - avatar
+ 1
Thanks maf , Taranjeet , Justus for the every support. Thanks again guys, I learned a lot.
23rd Mar 2020, 11:22 AM
DarkPrince
DarkPrince - avatar
+ 1
23rd Mar 2020, 11:23 AM
maf
maf - avatar
0
There is another problem now. Input p > Girl Input q > 19 Input r > tina Output ->) tina ! What's up Bruv ?
22nd Mar 2020, 5:13 PM
DarkPrince
DarkPrince - avatar