This community-built FAQ covers the “String Variables” exercise from the lesson “Introduction to Variables”.
Paths and Courses
This exercise can be found in the following Codecademy content:
FAQs on the exercise String 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 () 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 () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Now we can assign a new ‘bonus points’ variable that rewards the player for completing the round quicker:
bonus_points = 10000 / time_taken_seconds# Set bonus points to 1000 divided by the number of seconds it took to win the level
The next mistake is on page 4. There is a sentence fragment that makes it hard to comprehend the meaning of the lesson. Here is the link
https://www.codecademy.com/courses/learn-to-code-with-blockly/lessons/introduction-to-variables-learn-how-to-code/exercises/string-variables
"Let’s say we want two variables to hold parts of an a"
line1 = "123 Main Street"
city = "New York City"
I would like to continue with learning, but I want to make sure that I understand everything that is being said.
line1 = "123 Main Street"
city = "New York City"
print(line1 + ", " + city)
# Outputs "123 Main Street, New York City"
A string has been assigned to the line1 variable.
Similarly, another string has been assigned to the city variable. ", " is also a string (consisting of a comma character followed by a space character).
Since we want to concatenate/join three separate strings into a single string, so we need two + operators.
If we wanted to concatenate two strings into a single string, one + operator would be sufficient.
If we wanted to concatenate eight strings into a single string, we would need seven + operators.
As an aside, many languages have features such as string interpolation or template literals which allow for much easier creation of strings (as opposed to string concatenation involving many operators).