Monday, January 8, 2018

python decimal,float,rmax,min,ound,sorted,sum,int

from decimal import *
getcontext().prec = 4
print Decimal(1) / Decimal(7)
formatted = Decimal('0.142857')
print formatted
#getcontext().prec = 28
print Decimal('0.1428571428571428571428571429')
print Decimal('NaN')
print (Decimal('-Infinity') == '-Infinity')

data = map(Decimal, '1.34 1.87 3.45 2.35 1.00 0.03 9.25'.split())
print max(data)
print min(data)
print sorted(data)
print sum(data)
#Decimal('19.29')
a,b,c,d = data[:4]
print str(a), str(b), str(c), str(d)
#'1.34 1.87 3.45 2.35'
print float(a)
#1.34
print round(a, 1) # round() first converts to binary floating point
#1.3
print int(a)
#1
print (a * 5)
#Decimal('6.70')
print (a * b)
#Decimal('2.5058')
print (c % a)
#Decimal('0.77')
print Decimal(9).sqrt()
#3
print Decimal(3).exp()
#20.09
print Decimal('10').log10()
#1

result:::::::::::::::::::::::::::::::::::

PS D:\Projects\Python.Projects\maths> python main.py 0.1429 0.142857 0.1428571428571428571428571429NaNFalse9.25 0.03 [Decimal('0.03'), Decimal('1.00'), Decimal('1.34'), Decimal('1.87'), Decimal('2.35'), Decimal('3.45'), Decimal('9.25')] 19.29 1.34 1.87 3.45 2.35 1.34 1.3 1 6.70 2.506 0.77320.09 1 PS D:\Projects\Python.Projects\maths>

No comments: