I don't get what I did wrong on Lesson 12 For an If statement


Here is my code:

def using_control_once():
if raw_input("what") == "nothing" :
return "Success #1"

def using_control_again():
if raw_input("okay") == "okay" :
return "Success #2"

print using_control_once()
print using_control_again()

I reply nothing for the first raw_input and okay for the second. I get no error messages but the lesson says: Oops, try again. Make sure your if statements evaluate to True

Please help


Codecademy probably tests your functions and it won't expect you to ask for input, much less know what you want to reply.

In the future, make sure to format your code properly, nobody wants to reconstruct your code because you didn't do it right in your post.


@ionatan No,both input() and raw_input() works perfectly fine. Regarding the formatting his/hers code properly, really? aren't we here to help new ppl out with python?It's his 4th post here, so he/she is pretty new with the forum and it's FINE if he doesn't know how to format his/hers code since the person in question is new to programming in Python.

@titan995 It's not essentially wrong what you coded, if you try it out with the Python IDLE, both expression will return True.
As a temporary fix you could switch the code into some number check, you still can use the raw_input() added to int() like that: int(raw_input())

This could be a good example:

def using_control_once():
if int(raw_input()) > 20 :
return "Success #1"

def using_control_again():
if int(input()) == 10 :
return "Success #2"

print using_control_once()
print using_control_again()

If you simply want to keep your code you can simply delete the raw_input() and change it to "nothing" for your first if statement and "okay" for your second if statement, but raw_input() and input()#input() is used in Python3.x both works just fine.

If you need anything else do not hesitate to ask, even if your indentation is not right, we are all here to learn :smile:


Nobody has mentioned the input function, and it's not fine, it should be avoided because it is too powerful. Better to write what's supposed to happen. You can use it, but your code will immediately be of much lower quality.

Formatting is part of the code in Python and that's an important realization. It's also important to check ones post to see if it looks ok when one is trying to get help from people.


I don't see anywhere in the exercise that he should not use raw_input()/input() so it is totally fine, it simply means the guy here is learning at a better speed unlike others.
Formatting is indeed part of the code in python, I did format mine aswell still the post shows no formatting. Also he's new, and as a new member instead of throwing criticism at him(which is FINE, I repeat, it's fine giving critics, but did you help him in the end?) that result in no helpful criticism at all.


If you read my reply you'll find that it explains why taking input from the functions is preventing them from passing.

Functions should not have side-effects that are unrelated to their purpose/specification. For example, if I add 5 and 2 together, that shouldn't call peters phone, that would be incorrect.

And I do not recommend creating functions that behave differently based on whether they can get user input or not. Get that input from outside the functions instead. Easier yet is to hard-code the calls for testing as that way it only has to be typed once.


No, I do get your point cuz as such I've tried different pieces of code before replying him and raw_input("anything inside") == "okay" indeed won't let you pass thru the exercise.
Where I'm mostly referring to is, the exercise doesn't say anywhere you can't use it, so in a way it is fine to use it(the guy over here seems to know what he's doing, otherwise he would have not used a raw_input()).
Following the exercise is very important in learning here, I did wrote something similar in a different post to a guy who wasn't following the exercise and do things with his own idea of coding which doesn't help with growing in this enviroment, but personally I would've done the same and use some raw_input() to make the code funnier and enjoyable because coding is incredible.
With that said don't get me wrong, I agree with you but what I didn't really like was that you as a MOD could have given him some more helpful tips.. you got him/her stucked.


We should still be aiming to write good code that is designed to avoid bugs. eval and unadvertised side effects are both things that may lead to difficult-to-find bugs so they should be avoided and we should practice using solutions that cause less problems.


What indication do you have of that I got somebody stuck? If you are suggesting that I lead people in the wrong direction, do tell.

I am by no means obligated to completely solve things for people. On the contrary, when somebody gets stuck they need help in approaching the situation, not in getting their problem solved for them only to run into the same thing again.

I will intentionally hold information back when that means that they need to be asking more specific questions. Can't get anywhere before doing that.


No no we indeed need to write good code to avoid bugs I agree with that but is it really okay? Could be that I'm different but I do love making it harder especially when I code, bugs are a good way to help us grow and increase our coding skills and knowledge toward something. When you do something wrong the first thing you do is try to fix it, trial and error is what get us to advance to the next stage.Making something difficult sometimes isn't really the best option, but in certain cases it help us just getting better and have a good view of what we are actually doing.

No I wasn't referring that you lead him/her or any ppl in the wrong direction, but for example his/her indentation was wrong, and as a new person that just jumped into programming giving he/she out examples of what HE/SHE is actually supposed to do would be nice.
This forum is full of people who want to learn and are new to programming in general, they are not supposed to know everything that is implemented in the field of programming, that's where we come in, with that I'm not saying we must solve their problems STRAIGHT as it won't help them learning at all and it just kills the purpose of learning. This is my POV though, what I think might be irrelevant to you or any other people but this is how I love helping out people that are new in this field.
I hope everything is clear from my part as I do understand what you are referring to.
Have a nice day :smile: and Happy new year! :blush:


Making your code correct, scalable, and maintainable is plenty of challenge to develop your skill with, high quality code is already complicated aplenty. Fixing things until it's working is the wrong approach! We want to be able to reason about the correctness of a piece of code, not view it as a black box that we test for a while and then declare "working". So we avoid all the things that we have learned leads to trouble - things like globals and short names and too many variables in the same context and side effects and relying on undefined behaviour.

There will still be bugs to fix, don't worry.


Exactly why it is a challenge you will never be able to do it correctly untill it is fixed. How do you make your code correct? simply by fixing some mistakes and bugs untill it is correct but not perfect, perfection doesn't exist and it should not exist especially in the programming field.
Black box? umh this is quite interesting as an argument, IMO everything you do in your life is a black box, programming aswell, you can get the result expected from you, but there will always be something out of your expectations, exceptions is a daily thing, we will always try to fix something to make it correct and ultimately make it work.That's my POV again, there will always be people with different opinions and there isn't really a wrong approach, as I approached programming differently, there are people out there approaching differently than me aswell, programming is just amazing and as you said bugs will forever exist :smile: otherwise if something was easy what's the purpose of it? :smiley:
Have a nice day :smiley: