-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-numbers.py
58 lines (40 loc) · 1.15 KB
/
02-numbers.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/local/bin/python3
from math import sqrt
age = 45
print(type(age))
decimal = 5.4
print(type(decimal))
# Represent equations or expressions
algebra = 3 + 5j
print(type(algebra))
binary = 0B1010
print("Binary 0B1010 = %s" % (binary))
hexadecimal = 0Xff
print("Hexadecimal = %s" % (hexadecimal))
octal = 0O1010
print("Octal = %s" % (octal))
# Adding an integer and a float results in a float
print(age + decimal)
# Cast float to integer
print(age + int(decimal))
# Subtraction
print(age - 5)
# Multiplication
print(age * 3)
# Division
print(age / 2)
# Integer (Floor) Division
print(7 // 2)
# Float Division, if either number is a float the answer will be a float
print(age / 2.5)
# Modulo (Remainder after division)
print(age % 2)
# Square root method imported from the math module
print(sqrt(5))
# Insert comma separators for floating point and limit to 2 decimal places
print("${0:,.2f}".format(13459.87)) #0: is a positional argument
# followed by conversion to comma separated two decimals places
# Insert comma separators for integer
print(format(123456, ',d'))
# % multiplies decimal by 100 and displays with a % sign
print(format(0.5, '.0%'))