-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumeric.py
56 lines (42 loc) · 870 Bytes
/
Numeric.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
# WORKING WITH NUMERIC DATA
# Checking the type of a variable
num = 3
print(type(num))
num = 3.14
n1 = 3
n2 = 2
print(type(num))
# Basic Arithmetic
print(3 * 4)
print(4 / 2) # By default, division returns a float
print(4 / 3)
print(3 / 4) # Hence, there is no problem of improper fractions returning 0
print(3 + 2)
print(3 - 2)
print(3 % 2)
print(3 // 2) # floor division
print(3 ** 2) # (3 ** 2) = 3^2
print('3/2 = ' + str(n1/n2) + '\n' + '3//2 = ' + str(n1//n2))
# Increment and decrement
print(num)
num += 1
num -= 1
print(num)
# Numeric Functions
print(abs(-3))
print(round(3.55))
print(round(3.45, 1))
print(round(3.446, 2))
# Comparisons
print(n1 > n2)
print(n1 < n2)
print(n1 != n2)
print(n1 == n2)
print(n1 >= n2)
print(n1 <= n2)
# Casting strings to numbers
num_1 = '100'
num_2 = '200'
num_1 = int(num_1)
num_2 = int(num_2)
print(num_1 + num_2)