Python

math.floor

import math
*# Fractional number.*
n = *100.7*
*# Absolute value.*
print(**math.floor**(n))
print(**math.ceil**(n))100
101

Sum

Error

import math
*# Input list.*
values = [*0.9999999*, *1*, *2*, *3*]
*# Sum values in list.*
r = **sum**(values)
print(r)
*# Sum values with fsum.*
r = math.**fsum**(values)
print(r)6.999999900000001
6.9999999

import math
*# Truncate this value.*
value1 = *123.45*
truncate1 = **math.trunc**(value1)
print(truncate1)
*# Truncate another value.*
value2 = *345.67*
truncate2 = **math.trunc**(value2)
print(truncate2)123
345

Numbers

import math
*# Use math.pow method.*
a = **math.pow**(2, 3)
*# Use operator.*
b = 2 ** 3
*# Print results.*
print(a)
print(b)8.0
8

Memoize

import math
value1 = *9*
value2 = *16*
value3 = *100*
*# Use sqrt method.*
print(**math.sqrt**(value1))
print(math.sqrt(value2))
print(math.sqrt(value3))3.0
4.0
10.0

import math
*# This returns the value of e.*
print(**math.e**)
*# And this is pi.*
print(**math.pi**)2.718281828459045
3.141592653589793

abs

Round

Compound Interest

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on May 23, 2023 (edit).