New course! Every coder should learn Generative AI!
Try a free lesson0
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
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"
+ 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"
+ 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.
+ 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.
+ 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")
+ 2
Strings should have " "
+ 1
Tnx Taranjeet . Didn't work
Error:
Nameerror: boy is not defined
+ 1
Tnx maf. it worked perfectly now. Would you please explain again more elaborately.
+ 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?
+ 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.
+ 1
Syed Kabir np :)
0
There is another problem now.
Input p > Girl
Input q > 19
Input r > tina
Output ->) tina ! What's up Bruv ?