Jupyter Notebook practice exercise (page 6/12)

https://app.dataquest.io/m/349/project%3A-learn-and-install-jupyter-notebook/6/hidden-state

While doing this, I don’t understand this part:

" 6. Run the modified code, and then try to think about the state of the program just by using the code and the output you see.

  • You should notice that the state you deduced is contradictory to the output printed in the second cell — for instance, welcome(dq) is not supposed to print anything (because we didn’t use print() this time)."

It s probably simple but I can’t figure why ‘welcome (dq)’ doesn’t print anything but ‘welcome (jn)’ does

Thanks in advance for your help :slight_smile:

If when you defined the welcome function in the screen before you also created the dq, jn and py variables like this:

def welcome(a_string):
    print('Welcome to ' + a_string + '!')
    
dq = 'Dataquest'
jn = 'Jupyter Notebook'
py = 'Python'

Then when you modified the function, all the three variables should still be working even tough you did not initialized them in the current cell since they are already defined in a cell that was previously executed. If this is not happening, can you post more of your code?

Thank you for taking the time to answer.
I m not sure how to post my code, I took a print screen of what I m getting:

I don’t understand why I get ‘Welcome to Jupyter Notebook!’ as an output

Oh, that is beacuase you are not using the print() function. When you do not not use it your output will be only the output for your last line of code.

It will work like this:

print(welcome(dq))
print(welcome(jn))

or even:

print(welcome(dq))
welcome(jn)
2 Likes

Of course, it makes sense.
Thanks for your help and patience :innocent:

1 Like

No problem. If it solved your problem, would you mind marking my answer as solution? Thanks!

1 Like

trying to piggyback here, when I try to run the %history -p function, the only thing that comes up is that I have run that function. the instructions say that a “quite verbose” history should come up, but I get nada. did I somehow delete my history or something? this is my first use of the forum, not sure how to share my screen yet
thx

1 Like

Hi @ncarvey,

Welcome to Dataquest Community!

If running %history -p results in just >>> %history -p , that means you haven’t run any code prior to that. Here is an example:

Best,
Sahil

1 Like

Had the same doubt, didn’t thought that if print is not used then it will print last code. Thank you for your help. I searched the community before posting :slight_smile:
But how come it printed ‘Welcome to python!’ , when we actually delete that line of code assignment py = ‘Python’ as per the question @otavios.s?

Hello @uditchauhan,

Because you only deleted the code, but the variable is still stored in the memory. To delete the variable you need to run del py.

2 Likes

ah yes how can i forget that. Thanks for the heads up.

1 Like