Python | 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
| def convert_temp(from_: int, to_: int, value: float) -> float:
"""пересчет температур"""
if from_ == 0 and to_ == 1: # цельсия в Forengate
return value * 1.8 + 32
if from_ == 0 and to_ == 2: # цельсия в Kelvin
return value + 273.15
raise NotImplementedError
convert_temp.name = 'Температура'
convert_temp.units = ('c', 'Forengate', 'Kelvin')
def convert_mass(from_: int, to_: int, value: float) -> float:
pass
convert_mass.name = 'Вес'
convert_mass.units = ()
CONVERTERS = (convert_temp, convert_mass)
def main():
print('Что конвертим?')
for i, func in enumerate(CONVERTERS):
print(f'[{i}] {func.name}')
func = CONVERTERS[int(input('> '))]
print('Из какой единицы измерения конвертим?')
for i, unit in enumerate(func.units):
print(f'[{i}] {unit}')
from_ = int(input('> '))
print('В какую?')
for i, unit in enumerate(func.units):
print(f'[{i}] {unit}')
to_ = int(input('> '))
value = float(input('Величина:\n> '))
print('Получаем: %.3f' % func(from_, to_, value))
if __name__ == '__main__':
main() |
|
|