- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
Latest commit
149 lines (111 loc) · 2.24 KB
/
Copy pathcode.py
File metadata and controls
149 lines (111 loc) · 2.24 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
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
importmath
importos
defhello(a_name):
print("Hello! "+a_name)
defhello2(name_a, name_b):
print("Hello! "+name_a+" and "+name_b)
defsum_two(x,y):
z=x+y
returnz
defcircle_area(radius):
returnradius**2*math.pi
defmy_sum(a_list):
total=0
fornina_list:
total=total+n
returntotal
defmy_prod(a_list):
total=1
fornina_list:
total=total*n
returntotal
defmy_count(a_list):
total=0
fornina_list:
total=total+1
returntotal
defmy_count_less_5(a_list):
count=0
fornina_list:
ifn<5:
count=count+1
returncount
defmy_count_ones(a_list):
count=0
fornina_list:
ifn==1:
count=count+1
returncount
defis_list_empty(a_list):
ifmy_count(a_list)==0:
returnTrue
else:
returnFalse
defmy_max(a_list):
ifis_list_empty(a_list):
returnNone
b=a_list[0]
fornina_list:
ifn>b:
b=n
returnb
defget_filenames(a_dirname):
list_of_files=os.listdir(a_dirname)
all_files= []
forninlist_of_files:
full_path=os.path.join(a_dirname,n)
ifnotos.path.isdir(full_path):
all_files.append(full_path)
returnall_files
defflatten(a_list_with_lists):
new_list= []
fornina_list_with_lists:
ifisinstance(n,list):
foriinn:
new_list.append(i)
else:
new_list.append(n)
returna_list
defprint_right(a_list_with_lists):
new_list= []
fornina_list_with_lists:
ifisinstance(n,list):
foriinn:
print(i, end="")
else:
print(n, end="")
print()
defsingle_row_stars(number):
forninrange(number):
print("*",end="")
defsingle_row_of(number,string):
forninrange(number):
print(string, end="")
defsquare_of_stars(numbers):
forninrange(numbers):
forminrange(numbers):
print("*", end="")
print()
defrectangle_of_stars(rows, cols):
forninrange(rows):
forminrange(cols):
print("*", end="")
print()
deflist_by_2(a_list):
new_list= []
fornina_list:
new_list.append(n*2)
returnnew_list
defcreate_grid(size):
a_list= []
forrowinrange(size):
new_list= []
forcolumninrange(size):
new_list.append("-")
a_list.append(new_list)
returna_list
a= ["x","y","z","r"]
l=len(a)
foriinrange(len(a)):
a[i] ="rrr"
print("hi")