-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_test.py
More file actions
37 lines (21 loc) · 787 Bytes
/
format_test.py
File metadata and controls
37 lines (21 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
__author__ = 'k22li'
#format is a built-in functions from Python
# case 1:
a = 1234.56789
#^ stands for center justified displaying with the 10 digits length
# , stands for displaying of the 'Inclusions of thousands separator
# 2f stands for reserving the 2 digits after the
print format(a, '^10,.2f'), len(str(a))
# < stands for left justified displaying of 10 digits as the outputs
print format(a, '<10,.2f'), len(str(a))
#> stands for right justified displaying of the 10 digits as the outputs
print format(a, '>10,.2f'), len(str(a))
#fractions.Fraction
from fractions import Fraction
print Fraction(5, 4) # 5/4
print Fraction(6, 4) # 3/2
a = Fraction(5, 4)
b = Fraction(7, 16)
print a+b
c = a*b
print 'c.numerator: %s; c.denominator: %s'%(c.numerator, c.denominator)