import random from .base import Job class UnitConversionJob(Job): def get_name(self): return "PREVODY JEDNOTEK" def print_body(self, p): p.text("Preved:\n\n") # (from_unit, to_unit, factor) conversions = [ ('kg', 'g', 1000), ('km', 'm', 1000), ('m', 'cm', 100), ('cm', 'mm', 10), ('h', 'min', 60), ('min', 's', 60) ] for i in range(1, 11): u_from, u_to, factor = random.choice(conversions) # Randomly choose direction (multiply or divide) if random.choice([True, False]): # Big to Small (Multiply) val = random.randint(1, 20) question = f"{val} {u_from}" target_unit = u_to else: # Small to Big (Divide) - ensure clean integer target = random.randint(1, 20) val = target * factor question = f"{val} {u_to}" target_unit = u_from p.text(f"{i}) {question} = ____ {target_unit}\n\n") p.text("Hodne stesti!\n")