Commit 2425360f by Patryk Czarnik

kalkulator - wersja podstawowa

parent e7fd5793
...@@ -57,7 +57,24 @@ def rozmowa(request:HttpRequest) -> HttpResponse: ...@@ -57,7 +57,24 @@ def rozmowa(request:HttpRequest) -> HttpResponse:
context={'message': powitanie}) context={'message': powitanie})
def oblicz(arg1, arg2, operacja):
match operacja:
case '+': return arg1 + arg2
case '-': return arg1 - arg2
case '*': return arg1 * arg2
case '/': return arg1 / arg2
case '%': return arg1 % arg2
case '^': return arg1 ** arg2
case _: raise ValueError(f'Nieznana operacja {operacja}')
def kalkulator(request:HttpRequest) -> HttpResponse: def kalkulator(request:HttpRequest) -> HttpResponse:
wynik = 1313 wynik = 1313
try:
arg1 = int(request.GET['arg1'])
arg2 = int(request.GET['arg2'])
operacja = request.GET['operacja']
wynik = oblicz(arg1, arg2, operacja)
except Exception:
pass
return render(request, 'kalkulator.html', return render(request, 'kalkulator.html',
context={'wynik': wynik}) context={'wynik': wynik})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment