-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_3.py
117 lines (85 loc) · 2.56 KB
/
session_3.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def ds_not_mf():
new_list = []
for j in range(2000, 3200):
if j % 7 == 0 and j % 5 != 0:
new_list.append(j)
print(new_list)
def ds_not_mf_while():
start = 2000
end = 3200
count = start
while count <= end:
if count % 7 == 0 and count % 5 != 0:
print(count)
count += 1
def fibonacci(n):
if n == 0:
return n
elif n == 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
def seq_fibonacci(nterms):
# check if the number of terms is valid
if nterms <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(fibonacci(i))
def find_course_average():
summ = 0
student_a = {
"first" : "Amir",
"last": "Douzandeh",
"courses": 25,
"isStudent" : False,
}
student_b = {
"first" : "Ali",
"last": "Zen",
"courses": 32,
"isStudent" : True,
}
b = [student_a, student_b, student_a, student_b]
for student in b:
summ += student["courses"]
print(summ / len(b))
def titlecase(string):
index = 0
sepreted_string = string.split(" ")
for i in sepreted_string:
sepreted_string[index] = i[0].upper() + i[1:]
index += 1
print(' '.join(sepreted_string))
def write_in_file():
with open('sample.txt', mode='w') as file:
file.write('Hello World!')
def read_from_file():
with open('sample.txt', mode='r') as file:
for record in file:
print(record)
def append_in_file():
with open('sample.txt', mode='a+') as file:
file.write('\n Hello World! #4\n')
def write_stars_append():
number = int(input("Please Enter The Number: "))
for i in range(number):
with open('stars.txt', mode='a+') as file:
file.write(("*" * (i + 1) + '\n'))
def write_stars_write():
number = int(input("Please Enter The Number: "))
with open('stars.txt', mode='w') as file:
for i in range(number):
file.write(("*" * (i + 1) + '\n'))
def expand_stars():
total_lines = 0
number = int(input("Please Enter The Number: "))
with open('stars.txt', mode='r+') as file:
for count, line in enumerate(file):
pass
total_lines = count + 1
with open('stars.txt', mode='a+') as file:
for i in range(total_lines, number):
file.write(("*" * (i + 1) + '\n'))
expand_stars()