Daniel Nogueira
Posted on November 5, 2022
We can check the integer part of a real number, and one of the ways to do that is using the trunc()
method of the math
library.
Let's import the method:
from math import trunc
Then we read a real number and display its truncated value on the screen:
n = float(input('Real number: '))
print(f'Integer part: {trunc(n)}')
Another way is simply using the int()
function to display the value in its entirety.
print(f'Integer part: {int(n)}')
💖 💪 🙅 🚩
Daniel Nogueira
Posted on November 5, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
python Mastering Python’s __name__ and __main__: Understanding Script Execution and Module Imports
November 1, 2024
raspberrypi Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi
October 6, 2024