Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect definition of floor function for the type-cast to int example #55

Open
krishnakumarg1984 opened this issue Jul 15, 2024 · 0 comments

Comments

@krishnakumarg1984
Copy link

krishnakumarg1984 commented Jul 15, 2024

In the lesson in part 2, https://programming-24.mooc.fi/part-2/1-programming-terminology, it says:

temperature = float(input("Please type in a temperature: "))
print("The temperature is", temperature)
print("...and rounded down it is", int(temperature))

with the output block

Please type in a temperature: 5.15
The temperature is 5.15
...and rounded down it is 5

the text incorrectly says:

Notice the function always rounds down, and not according to the rounding rules in mathematics. This is an example of a floor function.

However, this is not the mathematical floor function. For a negative number such as -4.1, it produces -4, instead of -5, which is the true output from the mathematical floor function.

The python int() function merely does truncation, and not flooring. See this stackoverflow page for reference and an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant