What is the python float

Asked

Viewed 3,860 times

-2

I have the following code in Python but I don’t know what the float someone could help me?

peso = float(input('Digite seu peso (kg): '))

3 answers

2

Float is a variable that represents the real numbers. That is, values where we have 1.7, 2.8, 2.5... among others.

In the above case, the variable is float because it is a value in kgs for the user to put their weight.

Some time ago I created a Python application to perform the calculation of the IMC, where the user put his weight and height and the program printed on the screen his IMC.

  • Actually I’m also trying to develop an IMC calculator, thank you ;)

  • 4

    Correcting the nomenclature: float is a native class of the language to work with floating point.

  • I agree with Anderson’s answer, just remembering that floating point, are fractional numbers that in mathematics belong to the set of real numbers. If you need an example, I found a script for a Python IMC calculation program: https://www.portugal-a-programar.pt/forums/topic/72919-calculator-de-imc/ I hope I helped. Hug!

1


input takes a user keyboard input, and returns a string.

'1.5' would be the representation of a kilo and a half, but it is in quotes, characterizing a string, and if this value is used in a mathematical calculation will occur an error.

Now passing this string in the function float, causes it to be converted to floating number and thus the mathematical calculation becomes possible.

0

Numbers with a decimal point belong to a type called float, because these numbers are represented in a format called floating point

Browser other questions tagged

You are not signed in. Login or sign up in order to post.