6. Pop Quiz


Hello codecademy, please take a look @ this code.

My problem is when I type a name in the Console, it prints
off the else Please type a name line when I'm trying get it to
print original since the name is Greater than 0 and has no numbers.

If I didn't give enough information please just let me know & i'll update
you on whatever you need but other than that could anyone lend some help?

  • Thanks in Advance.


Firstly, you need to immediately set the variable -- not wait.

variable = raw_input("message")

What you're doing is first prompting, then not storing the answer. Then you're doing what you should be doing, but without a prompt.

Secondly, your conditional wouldn't work since the length of empty_string, at this point in time, will never be greater than zero. (You're never changing it, therefore its length is never changing.)

Thirdly, your else will only print a message and will never do what you're wanting. If you want that to function properly, you need to rewrite your code using a loop.

Something like this. I'll write in paraphrase so you can try and write yourself.

name = null
while ( (name == null) or len(name) == 0) {
  name = raw_input("What's the name of a vegetable?")
// Once out of the loop, we know *for sure* that name is **not** null and that it's length is **not** zero.
print "Cool " + name;


Okay, thanks for the quick reply. So

I'm going to go back a few steps & read everything again
hopefully help me realize what I missed. I haven't learned
loops yet so I dont understand what you're code is saying
too much jacob, but thanks for helping.

            If I have 
raw_input("What's you're name")
original = raw_input

My original variable wouldn't store what is typed
in the question?


Ehhh' I feel kind of dumb right now. I see what the
■■■■ I was doing wrong lol. Thanks for the help Jacob.


OK - in that case, don't rewrite. Let's try and stretch your brain a bit to use only conditionals.

To answer your question first: no.

raw_input() is a function (or method), which means it runs and returns some answer and then that's it. It doesn't store anything. You can see this in the same light as asking someone to do a task for you. For example, "Hey, Sarah, what's 2+2?" She might (hopefully) say "4". The next day, or a few days from then, however, it's likely she would forget I had even asked her the question. The same holds true for code. You call a function, it runs, and then it forgets.

This is why you need a variable to store, or remember, the value of whatever the function returned.

Make sense?

Now, since you haven't encountered loops yet -- no rewriting is needed. The program will simply terminate if it encounters that the original variable hasn't been populated correctly. Once you get to loops, you'll be able to make the program "keep going" (so to speak) until it gets something it can work with.


No problem. Also, as per the rules, please refrain from using expletives. (We have some young(er) users. :wink:)


Okay yes I understand what you were trying to explain to
me now. And yeah I apologize about that. Hey Jacob while
I have you here, would you recommend me going Pro with
Codecademy? I've been thinking about it & reading up on it a
bit. However, if I did purchase Pro, I was thinking of restarting
the whole java class to just brush up on the things i've learned
& understand it a bit better due to the help of having a live person
to chat with if I ever get stuck & break things down for me like you.


It is a good service, although you should stay with the free version for a while and really get to know the product before you jump aboard the paid version. This is just my personal opinion -- you are free to do whatever you want.

If you feel you really need the extra one-on-one help with an advisor, then feel free to go ahead and upgrade. Do keep in mind that the forums are and always will be a free source of support though -- the only (major) difference is the response time which can be slow.

(Also, no worries -- even if I'm not or another moderator is not participating in a topic, you can always "@" them and they'll come along eventually. e.x. @jacobsandersen)


Ah yeah I understand, thanks for the advice.
Will most likely familiarize myself with the code
a bit more.


Also, I should mention that you are probably guaranteed a certain level of response from an advisor. Because the forum is a free and public form of support, it is likely you may get answers from someone who doesn't actually know what they're doing. So keep that in mind as well :smile: