-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise-5.py
More file actions
55 lines (40 loc) · 1.13 KB
/
Exercise-5.py
File metadata and controls
55 lines (40 loc) · 1.13 KB
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
#Generate random values
import random
for i in range(3):
print(random.random())
for i in range(2):
print(random.randint(10,20))
#Random pick in a list
members = ['John', 'shubham', 'Robin', 'Pratekk']
leader = random.choice(members)
print(leader)
#Random dice
class Dice:
def roll(self):
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
return dice1,dice2 #return in Tupples, we dont need to add ( brackets ) for returning in tupples
dice = Dice()
print(dice.roll())
#Path Library Python
from pathlib import Path
# Absolute path - root from the harddisk
path = Path("ecommerce")
print(path.exists())
# path.mkdir() - create directory
# path.rmdir() - delete directory
path = Path()
print(path.glob('*')) #search all file in a current path
print(path.glob('*.xls'))
print(path.glob('*.ai'))
for file in path.glob('*.py'):
print(file)
# Python 3: Fibonacci series up to n
def fib(n):
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
fib(1000)
# 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987