Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reverzní kalkulačka, St 30.04.2014 09:28
- Loading branch information
1 parent
7bcaad8
commit 6b68bf3
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
|
||
x = raw_input('zadej cislo > ') | ||
|
||
print 4 + 'abc' | ||
|
||
|
||
try: | ||
print 5*7 | ||
print 5*12 | ||
|