FAQ: Learn Python: Syntax - Numbers

This community-built FAQ covers the “Numbers” 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 Numbers

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!

2 posts were split to a new topic: Why don’t I need paranthesis are around numbers?

2 posts were split to a new topic: Why don’t I need to define my variable as a float or integer?

6 posts were split to a new topic: I’m stuck on the numbers exercise?

2 posts were split to a new topic: Shouldn’t runtime be a float instead of an integer?

3 posts were split to a new topic: Can I have the solution?

Why do you need to define release_year?
If i just type “release_year_int = 2012”. This should be enough to know the number 2012 is about the release year. I could say like “print(release_year_int)” and the message would show “2012”.
What am I missing, why make it so extensive by writing another line?

5 Likes

Hi folks,

Having some trouble with this exercise. How do I define rating_out_of_ten?

By simply declaring it…

rating_out_of_ten = 9.5

I’m here to help, so during the exercise I was kind of lost but then if we think we are talking with a machine and the machine follows certain protocol you can think of trying answering in the order the machine is asking, after multiple attempts I decided to reply in this way.

wrong answer :x:
runtime = 20
release_year = 2020

correct answer :white_check_mark:
release_year = 2020
runtime = 20

wrong answer :x:
rating_out_of_ten = 7.5

correct answer :white_check_mark:
rating_out_of_10 = 7.5

1 Like

Define the release and runtime integer variables below:

release_year=2020

runtime= 1

print(“Release year:”+release_year)

print(“Runtime:”+runtime)

Define the rating_out_of_10 float variable below:

rating_out_of_10= 7.5

print(“Rating out of 10:”+rating_out_of_10)

How to fix this code?

Have you tried leaving some white space after the colons?

1 Like

I thought runtime was supposed to be used as a decimal number, not as an integer. why show us how to use an_int, and a_float if were not going to define that function in our code?

How can we print numbers as do in string
for eg:
release_year=2020
print(‘release year=’+release_year)

giving me#TypeError; must be str, not int

1 Like

When we want to concatenate a string with a data type other than a string, we have to use the str() function. str() returns the string version of the object passed into it. You can find more on this function here.

Welcome to the forums!

1 Like

I just want to confirm something: integers and float can be defined as anything right?

I can name my integer: Days of Weeks, balloons in a room, etc. ; and I can name my floats what I want (as long as format it properly): portion of pie eaten, fraction of time of movie watched, etc.

Yes, you can name your variables anything you’d like (of course, there are restrictions and naming conventions, like how variables names cannot start with numbers). You can represent anything you’d like using integers and floats, though of course, it would be more practical to represent things where these data types make sense.

1 Like

Variable Naming Conventions

days_of_week   =>  regular variable name using snake_case

Regular variables are not capitalized. They can be used to identify objects of any data type.

PI    =>  fixed constants

Constants are written in ALL CAPS.

Person    =>  class name

Class names are capitalized. Instances of the class are not.

def function:    =>  function name

Function names are not capitalized.

2 Likes

Tried everything i can but it keeps saying i havent defined release_year…any help would be appreciated

Define the release and runtime integer variables below:

#define a_release_year 1983

#define a_runtime 13

message_string = print(“The Big Screen’s Greatest Scenes Decided By A Machine.”)

a_release_year = 1983

a_runtime = 13

message_string = print(“release_year = 1983”)

message_string = print(“runtime = 13”)

message_string = print(‘a_release_year = 1983’)

message_string = print(‘a_runtime = 13’)

Define the rating_out_of_10 float variable below:

messge_string = print(‘a_rating_out_of_10 = 8.3’)

Scanning some of the above posts it seems everyone is using, release_year and runtime as their variable names. This would align with the error message, as well.

1 Like