diff --git a/01-uvod/ciferny-soucet.py b/01-uvod/ciferny-soucet.py new file mode 100755 index 0000000000000000000000000000000000000000..ebac204d2054ce4b8cb2be7a3a7beb36f666de0f --- /dev/null +++ b/01-uvod/ciferny-soucet.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +# Počítání ciferného součtu + +n = int(input()) +soucet = 0 + +while n > 0: + cislice = n % 10 + soucet += cislice + n = n // 10 + +print(soucet) diff --git a/01-uvod/euklides-modulici.py b/01-uvod/euklides-modulici.py new file mode 100755 index 0000000000000000000000000000000000000000..eddbf0dcb9fe003188a4c8fbf644f7807ee2c615 --- /dev/null +++ b/01-uvod/euklides-modulici.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# Největší společný dělitel: Euklidův algoritmus s modulem + +x = int(input()) +y = int(input()) + +while x > 0 and y > 0: + if x > y: + x %= y + else: + y %= x + +if x > 0: + print(x) +else: + print(y) diff --git a/01-uvod/euklides-odcitaci.py b/01-uvod/euklides-odcitaci.py new file mode 100755 index 0000000000000000000000000000000000000000..4bb7cbe5a60a75f9107600dc1d1d7cf1fec21757 --- /dev/null +++ b/01-uvod/euklides-odcitaci.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# Největší společný dělitel: Euklidův algoritmus s odčítáním + +x = int(input()) +y = int(input()) + +while x != y: + if x > y: + x -= y + else: + y -= x + +print(x) diff --git a/01-uvod/euklides-trikovy.py b/01-uvod/euklides-trikovy.py new file mode 100755 index 0000000000000000000000000000000000000000..17f98f453f4171e02995cd85a1c086bc41414bf8 --- /dev/null +++ b/01-uvod/euklides-trikovy.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +# Největší společný dělitel: Euklidův algoritmus s pár triky navíc + +x = int(input()) +y = int(input()) + +while y > 0: + x, y = y, x%y + +print(x) diff --git a/01-uvod/prvocisla-test.py b/01-uvod/prvocisla-test.py new file mode 100755 index 0000000000000000000000000000000000000000..77e86aa1977db5a2f28a2cea6ba45ef8dc2c8dc5 --- /dev/null +++ b/01-uvod/prvocisla-test.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +# Otestuje, zda číslo je prvočíslem + +n = int(input()) + +d = 2 +mam_delitele = False + +while d < n: + if n%d == 0: + print("Číslo", n, "je dělitelné", d) + mam_delitele = True + break + d += 1 + +if not mam_delitele: + print("Číslo", n, "je prvočíslo") diff --git a/01-uvod/prvocisla-vypis.py b/01-uvod/prvocisla-vypis.py new file mode 100755 index 0000000000000000000000000000000000000000..4ef3f9ba431637045fd036bbbfe208e5e1f9520f --- /dev/null +++ b/01-uvod/prvocisla-vypis.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# Vypíše všechna prvočísla od 1 do n + +n = int(input()) + +x = 2 +while x <= n: + d = 2 + mam_delitele = False + + while d < x: + if x%d == 0: + mam_delitele = True + break + d += 1 + + if not mam_delitele: + print(x) + + x += 1 diff --git a/01-uvod/zadavani-cislic.py b/01-uvod/zadavani-cislic.py new file mode 100755 index 0000000000000000000000000000000000000000..1b5e3f482c0e2bd6d1addf2bbf6c512899aa7e13 --- /dev/null +++ b/01-uvod/zadavani-cislic.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# Skládáme číslo po číslicích + +print("Zadávej číslice, ukonči -1:") +n = 0 + +while True: + cislice = int(input()) + if cislice < 0: + break # Vyskočíme z cyklu + n = 10*n + cislice + +print(n)