-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
49 lines (41 loc) · 1.69 KB
/
functions.py
File metadata and controls
49 lines (41 loc) · 1.69 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
# coding:utf-8
from data import *
def get_spaces():
for record in cars:
for key, value in record.items():
value_length = len(value)
translit_length = len(translits[key])
if spaces[key] < value_length or spaces[key] < translit_length:
if value_length > translit_length:
spaces[key] = value_length
else:
spaces[key] = translit_length
return spaces
def print_to_console():
if cars:
print "=============================================="
spaces = get_spaces()
print u'| id | Марка{make_space}| Модель{model_space}| Год выпкска{year_space}|'.format(
make_space=' '*(spaces['make']-len(translits['make'])+1),
model_space=' '*(spaces['model']-len(translits['model'])+1),
year_space=' '*(spaces['year']-len(translits['year'])+1),
)
for car in cars:
id_space = ' ' * (spaces['id']-len(car['id']))
make_space = ' ' * (spaces['make']-len(car['make']))
model_space = ' ' * (spaces['model']-len(car['model']))
year_space = ' ' * (spaces['year']-len(car['year']))
print u'| {id} | {make} | {model} | {year} |'.format(
id=car['id']+id_space,
make=car['make']+make_space,
model=car['model']+model_space,
year=car['year']+year_space
)
print "=============================================="
else:
print u'Нет записей'
def get_next_id():
if len(cars):
max_id = int(max(i['id'] for i in cars))
return str(max_id + 1)
return 0