Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 12.23.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Reeves K. 0661234567
Cage N. 0953451234
Depp J. 0507654321
DiCaprio L. 0664561234
Freeman M. 0509876123
10 changes: 10 additions & 0 deletions 12.24.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
3 red iron
5 green iron
5 blue wood
7 red cardboard
6 blue iron
2 green cardboard
4 red wood
8 yellow wood
2 blue cardboard
6 yellow iron
40 changes: 40 additions & 0 deletions 12.47.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
def check_indent(filename):
with open(filename) as f:
used = [(0, '')]
lines = f.readlines()

for line in lines:
stripped_line = line.lstrip()
indent = len(line) - len(stripped_line)

if indent > used[-1][0] and used[-1][1] == '':
print(line)
return False
if indent <= used[-1][0] and used[-1][1] == ':':
print(line)
return False
if indent < used[-1][0]:
while indent < used[-1][0]:
used.pop()
if indent != used[-1][0]:
print(line)
return False
if ':' == line.rstrip()[-1]:
used.append((indent, ':'))
else:
used.append((indent, ''))
elif ':' == line.rstrip()[-1]:
used.append((indent, ':'))
else:
used.append((indent, ''))
print(lines.index(line)+1, indent, used)

return True

if __name__ == '__main__':
filename = 'exercises/12.47.txt'
print(check_indent(filename))




32 changes: 32 additions & 0 deletions 12.47.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def check_indent(filename):
with open(filename) as f:
used = [(0, '')]
lines = f.readlines()
for line in lines:
stripped_line = line.lstrip()
indent = len(line) - len(stripped_line)
if indent > used[-1][0] and used[-1][1] == '':
print(line)
return False
if indent <= used[-1][0] and used[-1][1] == ':':
print(line)
return False
if indent < used[-1][0]:
while indent < used[-1][0]:
used.pop()
if indent != used[-1][0]:
print(line)
return False
if ':' == line.rstrip()[-1]:
used.append((indent, ':'))
else:
used.append((indent, ''))
elif ':' == line.rstrip()[-1]:
used.append((indent, ':'))
else:
used.append((indent, ''))
print(lines.index(line)+1, indent, used)
return True
if __name__ == '__main__':
filename = 'exercises/12.47.txt'
print(check_indent(filename))
63 changes: 63 additions & 0 deletions classwork4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Завдання 12.23
from collections import defaultdict

def phone_number(filename, name):
f = open(filename)
names = f.readlines()
name = name.split()
name = f'{name[0].title()} {name[1].title()}.'
for row in names:
if f'{row.split()[0]} {row.split()[1]}' == name:
return name, row.split()[2]
f.close()

return 'співробітника не знайдено'

filename = 'exercises/12.23.txt'
name = input("Введіть ім'я: ")
print(f'Телефон співробітника {phone_number(filename, name)[0]}: {phone_number(filename, name)[1]}')

# Завдання 12.24

def cubes_by_colours(filename):
f = open(filename)
rows = f.readlines()
colours_dict = defaultdict(int)
areas_dict = defaultdict(int)
cubes_dict = defaultdict(tuple)

for cube in rows:
colours_dict[cube.split()[1]] += 1
for cube in rows:
areas_dict[cube.split()[1]] += int(cube.split()[0])**3
for colour in areas_dict.keys():
cubes_dict[colour] = (f'Кількість кубиків: {colours_dict[colour]}',
f"Сумарний об'єм: {areas_dict[colour]}")
f.close()

return cubes_dict

def cubes_by_materials(filename):
f = open(filename)
rows = f.readlines()
wood_cubes = 0
iron_cubes = 0

for cube in rows:
if cube.split()[2] == 'wood' and int(cube.split()[0]) == 3:
wood_cubes += 1
if cube.split()[2] == 'iron' and int(cube.split()[0]) > 5:
iron_cubes += 1

return wood_cubes, iron_cubes


filename = 'exercises/12.24.txt'
for cube_colour, info in cubes_by_colours(filename).items():
print(f"{cube_colour}: {info}")

cubes = cubes_by_materials(filename)
print(f"\nКількість дерев'яних кубиків із ребром 3: {cubes[0]}")
print(f"Кількість металевих кубиків із ребром більшим за 5: {cubes[1]}")