FAQ: Variables - Reusing Values in Variables

This community-built FAQ covers the “Reusing Values in Variables” exercise from the lesson “Variables”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn How To Code

FAQs on the exercise Reusing Values in Variables

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

how do i get to know that what is the variable name and what if i forget it .

1 Like

you can always find the line where you defined the variable, to remind yourself of the variable name

Hi. I don’t know what to do in the first lesson. I typed rocks grass rocks or whatever in the blank rectangles, but nothing happened on the screen.

Could you please post a link to the exercise you’re referring to?

Thank you so much for responding. It was in Python, but I found out I really enjoy learning Java instead. Thank you anyway!!

1 Like

The code works in changing the shapes in the chart to what word u input. My question is how is that chart built up or if i wish to build same in my web page or blog, how do i do it?

You will need html, css and JS.

you will need listeners on the input fields, then with JS dynamically change the chart which you constructed with html & css

Okay, i will try that out, if i do have a problem, i would give an alert.

Can somebody explain this code:
my_number = 847595593392818109495
my_number * 2
my_number / 4
*** I would assume this is the code for block 1, 2, and 3? What is the = 8475--------, *2, and /4?

its multiplying (*) and division (/), so basic math operations.

Hello,

This is a new question, not a reply to a previous comment.

When writing variables in code, do they always have to have the underscore in the middle? In this lesson, they give the long number the variable name of my_number. Do you always have to write variable names like that? I’m a bit confused as to why it is written like that and notjust without the underscore, ie: mynumber?

Thanks,

The use of snake-case is very common in Python, with the chief aim to make variable names more readable. The underscore is not needed, but we can see the difference it makes when the names are rather verbose.

I’m REALLY starting at the beginning so will be asking lot of dummy questions. On Basics of Programming p.2 - the difference that I see is that I’m only typing in in each variable once instead of three times like I did in on the previous page - is that right?

yes, that is why the lesson is called reusing variable, for example:

one = 'grass'
two = 'rocks'
three = 'forest'

now i would just do:

draw(one) // draws grass
draw(two) // draws rocks
draw(three) // draws forest
draw(one) // draws grass
draw(two) // draws rocks
draw(three) // draws forest
draw(one) // draws grass
draw(two) // draws rocks
draw(three) // draws forest

and i get 9 fields like in the example, i reuse the grasslands (and the other ones as well)

and then i only need to change 'grass' to to 'rocks' in one place to change 3 fields

1 Like

Please explain why Variables are important to understand the foundation of code. To clarify I want to why replace the number with a variable?

Variable at the very basics of learning to program. We can store data in a variable, so we can programmatically access this value later. We don’t replace the number with a variable, we store the number in the variable.