From f0b3c89843914a3aa4864671ae9363c7c69dd5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=A0krab=C3=A1nek?= Date: Wed, 21 Sep 2022 14:02:38 +0200 Subject: [PATCH] add calc.py --- 01.py | 7 ++++++ calc.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 01.py create mode 100644 calc.py diff --git a/01.py b/01.py new file mode 100644 index 0000000..98ec520 --- /dev/null +++ b/01.py @@ -0,0 +1,7 @@ +import random + +for i in range(10): + if(i!=9): + print(random.randint(1,20),end=",") + else: + print(random.randint(1,20)) \ No newline at end of file diff --git a/calc.py b/calc.py new file mode 100644 index 0000000..10b4393 --- /dev/null +++ b/calc.py @@ -0,0 +1,75 @@ +import time + +def get_integer_value(n=1): + user_value = input(f"Napiš {str(n)}. číslo: ") + try: + return int(user_value) + except ValueError: + print(f"{user_value} není číslo. Zkus to znova.") + return get_integer_value(str(n)) + +def scitani(c1,c2): + vysledek=c1+c2 + print(str(c1) + " + " + str(c2) + " = " + str(vysledek)) + return(vysledek) + +def odecitani(c1,c2): + vysledek = c1-c2 + print(str(c1) + " -" + str(c2) + " = " + str(vysledek)) + return(vysledek) + +def nasobeni(c1,c2): + vysledek = c1*c2 + print(str(c1) + " * " + str(c2) + " = " + str(vysledek)) + return(vysledek) + +def deleni(c1,c2): + if c2 != 0: + vysledek = c1/c2 + print(str(c1) + " / " + str(c2) + " = " + str(vysledek)) + else: + print("Druhé číslo nesmí být nula") + return(vysledek) + +print("Vítej v kalkulačce") + +while True: + print("------------------") + print("Menu:") + print("a) sčítání") + print("b) odčítání") + print("c) násobení") + print("d) dělení") + print("all) vse dohromady") + print("e) EXIT") + vyber = input("napiš písmeno:") + + if vyber=="e": + exit(1) + + if vyber == "a" or vyber == "b" or vyber == "c" or vyber == "d" or vyber=="all": + cislo1 = get_integer_value() + cislo2 = get_integer_value(2) + vysledek = 0 + + if vyber=="a": + print("vybral sis sčítání") + scitani(cislo1,cislo2) + + elif vyber=="b": + print("vybral sis odčítání") + odecitani(cislo1,cislo2) + elif vyber=="c": + print("vybral sis násobení") + nasobeni(cislo1,cislo2) + elif vyber=="d": + print("vybral sis dělení") + deleni(cislo1,cislo2) + elif vyber=="all": + scitani(cislo1,cislo2) + odecitani(cislo1,cislo2) + nasobeni(cislo1,cislo2) + deleni(cislo1,cislo2) + + time.sleep(3) + \ No newline at end of file