-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.py
149 lines (111 loc) · 2.24 KB
/
code.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import math
import os
def hello(a_name):
print("Hello! " + a_name)
def hello2(name_a, name_b):
print("Hello! " + name_a + " and " + name_b)
def sum_two(x,y):
z = x + y
return z
def circle_area(radius):
return radius**2*math.pi
def my_sum(a_list):
total = 0
for n in a_list:
total = total + n
return total
def my_prod(a_list):
total = 1
for n in a_list:
total = total * n
return total
def my_count(a_list):
total = 0
for n in a_list:
total = total + 1
return total
def my_count_less_5(a_list):
count = 0
for n in a_list:
if n < 5:
count = count + 1
return count
def my_count_ones(a_list):
count = 0
for n in a_list:
if n == 1:
count = count + 1
return count
def is_list_empty(a_list):
if my_count(a_list)==0:
return True
else:
return False
def my_max(a_list):
if is_list_empty(a_list):
return None
b = a_list[0]
for n in a_list:
if n > b:
b = n
return b
def get_filenames(a_dirname):
list_of_files = os.listdir(a_dirname)
all_files = []
for n in list_of_files:
full_path = os.path.join(a_dirname,n)
if not os.path.isdir(full_path):
all_files.append(full_path)
return all_files
def flatten(a_list_with_lists):
new_list = []
for n in a_list_with_lists:
if isinstance(n,list):
for i in n:
new_list.append(i)
else:
new_list.append(n)
return a_list
def print_right(a_list_with_lists):
new_list = []
for n in a_list_with_lists:
if isinstance(n,list):
for i in n:
print(i, end ="")
else:
print(n, end = "")
print()
def single_row_stars(number):
for n in range(number):
print("*",end = "")
def single_row_of(number,string):
for n in range(number):
print(string, end = "")
def square_of_stars(numbers):
for n in range(numbers):
for m in range(numbers):
print("*", end = "")
print()
def rectangle_of_stars(rows, cols):
for n in range(rows):
for m in range(cols):
print("*", end = "")
print()
def list_by_2(a_list):
new_list = []
for n in a_list:
new_list.append(n*2)
return new_list
def create_grid(size):
a_list = []
for row in range(size):
new_list = []
for column in range(size):
new_list.append("-")
a_list.append(new_list)
return a_list
a = ["x","y","z","r"]
l = len(a)
for i in range(len(a)):
a[i] = "rrr"
print("hi")