Тема: Конвертація з десятичної системи у старовинні
Римська
Єгипетська
Вавилонська
Слов'янська
Майа
Іонійська
from copy import deepcopy
coding_rim = zip(
[1000,900,500,400,100,90,50,40,10,9,5,4,1],
["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
)
def convert_to_roman(num):
if num <= 0 or num >= 4000 or int(num) != num: return None
result = []
for d, r in deepcopy(coding_rim):
while num >= d:
result.append(r)
num -= d
return ''.join(result)
coding_egip = zip(
[1000, 100, 10, 1],
["Лотос", "Петля мотузки", "Підкова, перевернута донизу", "Одна риска"]
)
def convert_to_egipet(num):
if num <= 0 or num > 9000 or int(num) != num: return None
result = []
for d, r in deepcopy(coding_egip):
while num >= d:
result.append(r)
num -= d
return ' | '.join(result)
vavilone_zip = zip(
[10, 1],
["<", "I"]
)
def convert_to_vavilone(num):
result = []
number_converted = []
while num > 59:
num, res = divmod(num, 59)
number_converted.append(res)
number_converted.append(num)
number_converted.reverse()
zip = [deepcopy(vavilone_zip) for _ in range(len(number_converted))]
for i in range(len(number_converted)):
result.append(f"Ряд {len(number_converted)-(i)}: ")
for d, r in zip[i]:
while number_converted[i] >= d:
result.append(r)
number_converted[i] -= d
result.append("\n")
return ''.join(result)
slovanska_zip = zip(
[1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
['҂а', 'Ц', 'ω', 'Ѱ', 'X', 'Ф', 'У', 'Т', 'С', 'Р', 'Ч', 'П', 'О', 'ѯ', 'Н', 'М', 'Л', 'К', 'Ѳі', 'Иі', 'Зі', 'Sі', 'Єі', 'Ді', 'Гі', 'Ві', 'Аі', "Ї", "Ѳ", "И", "З", "S", "Є", "Д", "Г", "В", "А"]
)
def convert_to_slovanska(num):
if num <= 0 or num > 1999 or int(num) != num: raise ValueError('Input should be an integer between 1 and 1999')
result = []
for d, r in deepcopy(slovanska_zip):
while num >= d:
result.append(r)
num -= d
return ''.join(result)
maya_zip = zip(
[5, 1],
["горизонтальна риска", "точка"]
)
def convert_to_maya(num):
result = []
number_converted = []
while num > 19:
num, res = divmod(num, 20)
number_converted.append(res)
number_converted.append(num)
number_converted.reverse()
zip = [deepcopy(maya_zip) for _ in range(len(number_converted))]
for i in range(len(number_converted)):
result.append(f"Ряд {len(number_converted)-(i)}: ")
temp = 0
for d, r in zip[i]:
while number_converted[i] >= d:
result.append(r)
number_converted[i] -= d
temp += 1
if temp == 0: result.append("Пуста ракушка")
result.append("\n")
return ' '.join(result)
ioniska_zip = zip(
[9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700,600, 500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
["͵Θ", "͵H", "͵Z", "͵Ϛ", "͵Ε", "͵Δ", "͵Γ", "͵Β", "͵Α", "ϡʹ", "ωʹ", "ψʹ", "χʹ", "φʹ", "υʹ", "τʹ", "σʹ", "ρʹ", "ϟʹ" "πʹ", "οʹ", "ξʹ", "νʹ", "μʹ", "λʹ", "κʹ", "ιʹ", "θʹ", "ηʹ", "ζʹ", "ϝʹ", "εʹ", "δʹ", "γʹ", "βʹ", "αʹ"]
)
def convert_to_ioniska(num):
result = []
if num <= 0 or num > 9999 or int(num) != num: raise ValueError('Input should be an integer between 1 and 9999')
result = []
for d, r in deepcopy(ioniska_zip):
while num >= d:
result.append(r)
num -= d
return ''.join(result)
DATA_INFO_R = {
"r" : "Римська",
"ig" : "Єгипетська",
"v" : "Вавилонська",
"s" : "Словянська",
"m" : "Майа",
"io" : "Іонійська"
}
DATA_INFO = ["r", "ig", "v", "s", "m", "io"]
def main():
print("захистів не писав тому вводьте все з 1-го разу :3")
while 1:
number = int(input("Введіть число: "))
for i in range(len(DATA_INFO)): print(f"{DATA_INFO[i]}: {DATA_INFO_R[DATA_INFO[i]]}")
data_info = input("Введіть код мови: ")
print(f"Число у {DATA_INFO_R[data_info]} чисельна система: ", end = '')
if data_info == "r": print(convert_to_roman(number))
elif data_info == "ig": print(convert_to_egipet(number))
elif data_info == "v": print(f"\n1 - I - прямий клин\n10 - < - лежачий клин\n", convert_to_vavilone(number))
elif data_info == "s": print(convert_to_slovanska(number))
elif data_info == "m": print(convert_to_maya(number))
elif data_info == "io": print(convert_to_ioniska(number))
if __name__ == "__main__": main()