-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6 - numbers.py
More file actions
50 lines (41 loc) · 861 Bytes
/
6 - numbers.py
File metadata and controls
50 lines (41 loc) · 861 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
There are 3 numeric types in pythn
- int
- float
- complex
"""
x = 1 # int
y = 2.8 # float
z = 1j # complex
# Int
"""
Int, or integer, is a whole number, positive or negative, without
decimals, of unlimited length.
"""
# Float
"""
Float, or "floating point number" is a number, positive or negative,
containing one or more decimals.
"""
# Complex
"""
Complex numbers are written with a "j" as the imaginary part:
"""
# Type Conversion
x = 1 # int
y = 2.8 # float
z = 1j # complex
# convert int to float
a = float(x)
# convert float to int
b = int(y)
# convert int to complex
c = complex(x)
# Generate Random number
"""
Python does not have a random() function to make a random number,
but Python has a built-in module called random that can be used
to make random numbers:
"""
import random
print(random.randrange(1, 10))