FAQ: Learn Python: Syntax - Review

This community-built FAQ covers the “Review” exercise from the lesson “Learn Python: Syntax”.

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

Computer Science
Data Science

FAQs on the exercise Review

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!

3 posts were split to a new topic: What is a solution example for the review?

Hi I would like to add a variable inside a string as below:

my_age = 40
greeting = "Hi "
name = "Jack "
age = ", I am "*my_age*" years old!"
greeting_with_name = greeting + name + age

I would like to add the my_age variable in the middle of the string for the age variable. But this code comes up with an error.

Thanks for any help

1 Like

It’s concatenation so you should use the ‘+’ sign!

1 Like

Is it possible to use print multiple times? If not, why is that the case?

How do I get half_my_age to be a whole number in the code below?

my_age = 48

half_my_age = my_age / 2

greeting = “Hi”

name = “Peter”

greeting_with_name = greeting + " " + name +"!"


print(“I am” + " " + str(half_my_age) + " "+ “years old.” + " ")

1 Like

That is a float so how do we convert a float to an integer?
Safest way to convert float to integer in python?

This is what I used to get to move on. Side note…I actully put greeting and name in quotes, wrong output, but it still passed me

my_age = 41

half_my_age = 21.5

greeting = ("Whats up, my name is ")

name = (‘Your Name’)

greeting_with_name = (greeting + name)




After looking at yours I want to take mine down, lol. Nice work , I forgot all about the str().

1 Like

i dont understand why a float number was returned for my_age = 45 …half_my_age = my_age /2
prints = 22.5
i thought you had to specifically specify to return a float number or you would only get a rounded integer?

If you return my_age then it in itself is a float. 45 / 2 = 22.5. It’s doing just that. If you want to round it then one way is to cast it as an integer.

i dont understand. ‘1’ is an integer. 1.2 is a float. if my age is 45, an integer, why does it return a float number. thanks for answering ! i’ll get it, im just a little slow and thick. my whole life has avoided logic ,math and numbers lol

In Python 3, an expression with the division operator (/) will return a float if the quotient is a float. It’s as simple as that — no matter if the dividend and divisors are integers or floats.

>>> 5 / 2

You may be confused if you learnt Python 2. In Python 2, the same operator (/) will return an integer assuming both the dividend and divisor are integers.

>>> 5 / 2

In both Python 2 and 3, you can use integer division (//) to return an integer no matter whether the dividend and divisor are integers or floats.


Python 2

>>> 5 // 2
>>> 5.0 // 2.0

Python 3

>>> 5 // 2
>>> 5.0 // 2.0

how come

my_age = 23

half_my_age = 23**.05

greeting = “hallo”

name = “charlie steffens”

greeting_with_name = greeting, name

comes out as (‘hallo’, ‘charlie steffens’)

but if i use greeting_with_name = greeting + name
it comes out as hallocharlie steffens

They are two different kinds of syntax and they ask the computer to do something different. The second option with the + operator is a way to concatenate two strings. So the output is just a new single string consisting of the content of those two strings joined together.

Using a comma as you did with the first option on the other hand will end up producing a tuple which is the most basic kind of sequence in Python. So you wind up with a tuple consisting of two elements which are those two original strings in order.