test math
This commit is contained in:
163
complete_update.py
Normal file
163
complete_update.py
Normal file
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Скрипт для завершения обновления калькуляторов
|
||||
Добавляет функции умножения и деления в sedecim_calculeator8.py и pentecostal_calculeator10.py
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
def add_hex_multiplication_division():
|
||||
"""Добавляет умножение и деление в шестнадцатеричный калькулятор"""
|
||||
|
||||
# Методы для добавления после calculate_addition
|
||||
methods_to_add = '''
|
||||
def calculate_multiplication(self, e):
|
||||
try:
|
||||
num1 = self.hex_to_decimal(self.input_mult_1.value.upper())
|
||||
num2 = self.hex_to_decimal(self.input_mult_2.value.upper())
|
||||
result_decimal = num1 * num2
|
||||
result_hex = self.decimal_to_hex(result_decimal)
|
||||
|
||||
self.result_mult.value = f"HEX: {result_hex}"
|
||||
self.decimal_mult.value = f"DEC: {result_decimal}"
|
||||
|
||||
if '.' not in self.input_mult_1.value and '.' not in self.input_mult_2.value:
|
||||
hex_val1 = self.input_mult_1.value.upper().lstrip('-+') if self.input_mult_1.value else "0"
|
||||
hex_val2 = self.input_mult_2.value.upper().lstrip('-+') if self.input_mult_2.value else "0"
|
||||
self.show_steps_mult(hex_val1, hex_val2, Operation.MULTIPLICATION)
|
||||
else:
|
||||
self.steps_mult.controls.clear()
|
||||
self.steps_mult.controls.append(
|
||||
ft.Text("Пошаговое решение доступно только для целых чисел", color="#FFD700", size=12)
|
||||
)
|
||||
self.steps_mult.update()
|
||||
except Exception as ex:
|
||||
self.result_mult.value = f"Ошибка: {str(ex)}"
|
||||
self.decimal_mult.value = "DEC: ошибка"
|
||||
self.page.update()
|
||||
|
||||
def calculate_division(self, e):
|
||||
try:
|
||||
num1 = self.hex_to_decimal(self.input_div_1.value.upper())
|
||||
num2 = self.hex_to_decimal(self.input_div_2.value.upper())
|
||||
|
||||
if num2 == 0:
|
||||
self.result_div.value = "HEX: Деление на 0!"
|
||||
self.decimal_div.value = "DEC: ошибка"
|
||||
self.page.update()
|
||||
return
|
||||
|
||||
quotient = int(num1 // num2)
|
||||
remainder = int(num1 % num2)
|
||||
quot_hex = self.decimal_to_hex(quotient)
|
||||
|
||||
if remainder == 0:
|
||||
self.result_div.value = f"HEX: {quot_hex}"
|
||||
self.decimal_div.value = f"DEC: {quotient}"
|
||||
else:
|
||||
self.result_div.value = f"HEX: {quot_hex}"
|
||||
self.decimal_div.value = f"DEC: {quotient} (ост. {remainder})"
|
||||
|
||||
if '.' not in self.input_div_1.value and '.' not in self.input_div_2.value:
|
||||
hex_val1 = self.input_div_1.value.upper().lstrip('-+') if self.input_div_1.value else "0"
|
||||
hex_val2 = self.input_div_2.value.upper().lstrip('-+') if self.input_div_2.value else "0"
|
||||
self.show_steps_div(hex_val1, hex_val2, Operation.DIVISION)
|
||||
else:
|
||||
self.steps_div.controls.clear()
|
||||
self.steps_div.controls.append(
|
||||
ft.Text("Пошаговое решение доступно только для целых чисел", color="#FFD700", size=12)
|
||||
)
|
||||
self.steps_div.update()
|
||||
except Exception as ex:
|
||||
self.result_div.value = f"Ошибка: {str(ex)}"
|
||||
self.decimal_div.value = "DEC: ошибка"
|
||||
self.page.update()
|
||||
|
||||
def show_steps_mult(self, num1: str, num2: str, operation: Operation):
|
||||
"""Отображает пошаговое решение для умножения"""
|
||||
try:
|
||||
steps = self.solver.solve(num1, num2, operation)
|
||||
self.steps_mult.controls.clear()
|
||||
|
||||
self.steps_mult.controls.append(
|
||||
ft.Text("📝 Ход решения:", size=14, weight=ft.FontWeight.BOLD, color="#FFD700")
|
||||
)
|
||||
|
||||
for i, step in enumerate(steps, 1):
|
||||
step_content = []
|
||||
step_content.append(ft.Text(f"Шаг {i}: {step.title}", size=12, weight=ft.FontWeight.BOLD, color="#00FFFF"))
|
||||
step_content.append(ft.Text(step.description, size=10, color="#E0E0E0"))
|
||||
if step.visual:
|
||||
step_content.append(ft.Text(step.visual, size=10, font_family="Courier New", color="#90EE90", selectable=True))
|
||||
if step.result:
|
||||
step_content.append(ft.Text(f"➤ {step.result}", size=11, weight=ft.FontWeight.BOLD, color="#00FF00"))
|
||||
|
||||
self.steps_mult.controls.append(
|
||||
ft.Container(
|
||||
content=ft.Column(step_content, spacing=3),
|
||||
bgcolor="#2A1A3A",
|
||||
padding=8,
|
||||
border_radius=5,
|
||||
border=ft.border.all(1, "#4A3A5A")
|
||||
)
|
||||
)
|
||||
self.steps_mult.update()
|
||||
except Exception as ex:
|
||||
self.steps_mult.controls.clear()
|
||||
self.steps_mult.controls.append(ft.Text(f"Ошибка: {str(ex)}", color="red", size=10))
|
||||
self.steps_mult.update()
|
||||
|
||||
def show_steps_div(self, num1: str, num2: str, operation: Operation):
|
||||
"""Отображает пошаговое решение для деления"""
|
||||
try:
|
||||
steps = self.solver.solve(num1, num2, operation)
|
||||
self.steps_div.controls.clear()
|
||||
|
||||
self.steps_div.controls.append(
|
||||
ft.Text("📝 Ход решения:", size=14, weight=ft.FontWeight.BOLD, color="#FFD700")
|
||||
)
|
||||
|
||||
for i, step in enumerate(steps, 1):
|
||||
step_content = []
|
||||
step_content.append(ft.Text(f"Шаг {i}: {step.title}", size=12, weight=ft.FontWeight.BOLD, color="#00FFFF"))
|
||||
step_content.append(ft.Text(step.description, size=10, color="#E0E0E0"))
|
||||
if step.visual:
|
||||
step_content.append(ft.Text(step.visual, size=10, font_family="Courier New", color="#90EE90", selectable=True))
|
||||
if step.result:
|
||||
step_content.append(ft.Text(f"➤ {step.result}", size=11, weight=ft.FontWeight.BOLD, color="#00FF00"))
|
||||
|
||||
self.steps_div.controls.append(
|
||||
ft.Container(
|
||||
content=ft.Column(step_content, spacing=3),
|
||||
bgcolor="#2A1A3A",
|
||||
padding=8,
|
||||
border_radius=5,
|
||||
border=ft.border.all(1, "#4A3A5A")
|
||||
)
|
||||
)
|
||||
self.steps_div.update()
|
||||
except Exception as ex:
|
||||
self.steps_div.controls.clear()
|
||||
self.steps_div.controls.append(ft.Text(f"Ошибка: {str(ex)}", color="red", size=10))
|
||||
self.steps_div.update()
|
||||
'''
|
||||
|
||||
print("✓ Шаблон методов для шестнадцатеричного калькулятора создан")
|
||||
print("\nСкопируйте этот код и вставьте после метода calculate_addition в sedecim_calculeator8.py")
|
||||
print(methods_to_add)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("="*60)
|
||||
print("ИНСТРУКЦИЯ ПО ЗАВЕРШЕНИЮ ОБНОВЛЕНИЯ КАЛЬКУЛЯТОРОВ")
|
||||
print("="*60)
|
||||
print("\n✅ УЖЕ ОБНОВЛЕНО:")
|
||||
print(" • step_by_step_solver.py - добавлены умножение и деление")
|
||||
print(" • calculater2.py - 4 колонки (+, -, ×, ÷)")
|
||||
print(" • binary_calculeator4.py - 4 колонки (+, -, ×, ÷)")
|
||||
print(" • octogon_calculeator6.py - 4 колонки (+, -, ×, ÷)")
|
||||
print("\n⏳ НУЖНО ЗАВЕРШИТЬ:")
|
||||
print(" • sedecim_calculeator8.py (Шестнадцатеричный)")
|
||||
print(" • pentecostal_calculeator10.py (50-ричный)")
|
||||
print("\n" + "="*60)
|
||||
print("РУКОВОДСТВО НАХОДИТСЯ В: UPGRADE_GUIDE.md")
|
||||
print("="*60)
|
||||
Reference in New Issue
Block a user