from django import forms

OPERATIONS = [
    ('add', '+'),
    ('subtract', '−'),
    ('multiply', '×'),
    ('divide', '÷'),
]


class CalculatorForm(forms.Form):
    num1 = forms.FloatField(label='First number')
    operation = forms.ChoiceField(choices=OPERATIONS)
    num2 = forms.FloatField(label='Second number')

    def clean(self):
        cleaned = super().clean()
        if cleaned.get('operation') == 'divide' and cleaned.get('num2') == 0:
            raise forms.ValidationError('Cannot divide by zero.')
        return cleaned
