Why is it invalid to add a period after a variable name to make it a float?

Actually, there’s no separate math coprocessor since the i386. The floating-point unit (FPU) is integrated into the CPU itself.

Furthermore, the FPU deals with floating-point operations (and not “number operations”).
Integer math is performed by the integer units. Floating-point and high-level math operations, like trigonometric functions, logarithms, roots are offloaded to the FPU.

Regarding real numbers: any number that can be expressed in the form of (a+ib) is a real number.
You can’t store a real number on a computer, because they have an infinite number of decimal places. Floating point is a CS-concept, an approximation that uses a finite number of places.
So no, you can’t compare floats (a computer science concept) and real numbers (a math concept).


I used the method float() to get the result in float, float(cucumbers). but it is still not working in my case.

*Your line 7 needs to be = float(cucumbers)/num_people. Because, using float(), you must tell it (in your line 7) that the variable IS potentially a decimal. And those guys said (amongst them), to use the numerator for float() [even though it works putting float() at both or either].
*Your variable name that captures the decimal value suggests it is made of a float, but notice that both your variables (whole_cucumbers and float_cucumbers) are asking for the same thing. And getting the same thing (which you did notice).

can i use
float cucumbers=10
I came from c++ and i am so confused

Here’s an interesting little error that can arise from using float incorrectly:

float_cucumbers_per_person = float(cucumbers/ num_people)

print float_cucumbers_per_person

This will print out a floating point result of 16.0 This is because the two variables inside the float brackets perform an integer divide before they get converted into a float. Be careful where you do your float conversion or you could get the wrong answer but have no error report.

This is the issue that Python 3 addresses. Fortunately Python 2 is nearly at its swansong, riding off into the sunset this coming January.

Hello, @array3129720301, and welcome to the Codecademy Forums!

Yes, it is always important to consider the order in which operations that evaluate an expression are performed. Though the division operation you presented is performed in what is perhaps a more intuitive manner in Python 3 than in Python 2, complex expressions with multiple operators may sometimes present challenges even in Python 3 related to the order of operations.

See Operator precedence for an official reference. Regarding that reference table, the operations are performed in order from the highest precedence ones listed at the bottom to the lowest precedence ones at the top.

Edited on November 10, 2019 to emphasize that the table lists precedences with highest at the bottom and lowest at the top

I would prefer you type the reference of the value instead the value itself, as below…

preferably>> whole_cucumbers_per_person = cucumbers / num_people

Preferably>> float_cucumbers_per_person = float(cucumber) / num_people

I prefer this way bcuz variables can change during the process and Python has the ability to update the variable whenever there is a change in its value, this is one the beauties of the programming, you let it do things automatically! :slight_smile:

1 Like

I’m new to this. It made sense to me. :wink:
the 3 - 4 examples helped. I just printed the wrong thing and was wondering why it was not showing the correct one until i realized my mistake