Ad
Code
Diff
  • def calculator(num1, num2, kind):
        operations = {
            '+': lambda x, y: x + y,
            '-': lambda x, y: x - y,
            '*': lambda x, y: x * y,
            '/': lambda x, y: x / y if y != 0 else float('inf'),
            '//': lambda x, y: x // y if y != 0 else float('inf'),
            '%': lambda x, y: x % y if y != 0 else float('nan'),
            '**': lambda x, y: x ** y,
        }
    
        if kind not in operations:
            raise ValueError(f"Unsupported operation: {kind}")
        
        return operations[kind](num1, num2)
    
    • def calculator(num1, num2, kind):
    • return eval(f'{num1} {kind} {num2}')
    • operations = {
    • '+': lambda x, y: x + y,
    • '-': lambda x, y: x - y,
    • '*': lambda x, y: x * y,
    • '/': lambda x, y: x / y if y != 0 else float('inf'),
    • '//': lambda x, y: x // y if y != 0 else float('inf'),
    • '%': lambda x, y: x % y if y != 0 else float('nan'),
    • '**': lambda x, y: x ** y,
    • }
    • if kind not in operations:
    • raise ValueError(f"Unsupported operation: {kind}")
    • return operations[kind](num1, num2)
Code
Diff
  • class Movie:
        def __init__(self, title, rating):
            self.title = title
            self.rating = rating
    
        def is_hit(self):
            return "hit" if self.rating >= 8 else "flap"
    
        def display_info(self):
            print(f"title: {self.title} rating: {self.rating}")
    
    
        
    • class movie:
    • class Movie:
    • def __init__(self, title, rating):
    • self.title = title
    • self.rating = rating
    • def is_hit(self):
    • if self.rating >= 8:
    • return "hit"
    • else:
    • return "flap"
    • return "hit" if self.rating >= 8 else "flap"
    • def display_info(self):
    • print(f" title: {self.title} rating: {self.rating}")
    • print(f"title: {self.title} rating: {self.rating}")