Skip to content

Commit

Permalink
reverzní kalkulačka, St 30.04.2014 09:28
Browse files Browse the repository at this point in the history
  • Loading branch information
MarrekNozka committed Apr 30, 2014
1 parent 7bcaad8 commit 6b68bf3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Binary file added .kalkulacka.py.swp
Binary file not shown.
55 changes: 55 additions & 0 deletions kalkulacka.py
@@ -0,0 +1,55 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# Soubor: kalkulacka.py
# Datum: 30.04.2014 08:42
# Autor: Marek Nožka, nozka <@t> spseol <d.t> cz
# Licence: GNU/GPL
# Úloha: jednoduchá reverzní kalkulačka
############################################################################

from __future__ import unicode_literals

zasobnik = []


def zpracujVstup():
global zasobnik
vstup = raw_input('>> ').strip()
if vstup == '':
print zasobnik
return
elif vstup in '+-*/':
if len(zasobnik) >= 2:
b = zasobnik.pop()
a = zasobnik.pop()
else:
print ">>>> V zásobníku je málo čísel"
print zasobnik
return
if vstup == '+':
zasobnik += [a+b]
elif vstup == '-':
zasobnik += [a-b]
elif vstup == '*':
zasobnik += [a*b]
elif vstup == '/':
zasobnik += [a/b]
return
try:
vstup = float(vstup)
zasobnik += [vstup]
except ValueError:
print ">>>> Zadej jedno reálné číslo"


while True:
try:
zpracujVstup()
except EOFError:
exit(0)
except KeyboardInterrupt:
print "Aplikace ukončena uživatelem"
exit(1)
# except:
# print "ERROR: neznámá chyba"
# exit(2)
3 changes: 3 additions & 0 deletions vyjimky.py
Expand Up @@ -4,6 +4,9 @@

x = raw_input('zadej cislo > ')

print 4 + 'abc'


try:
print 5*7
print 5*12
Expand Down

0 comments on commit 6b68bf3

Please sign in to comment.