Skip to content
Open

U2 #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doma1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
veky = [35, 12, 44, 11, 18, 21, 28, 18]

do_osmnacti = [int(18-vek) for vek in veky]
print(do_osmnacti)

plnoletost = [(vek >= 18) for vek in veky]
print(plnoletost)

osmnact = [(vek == 18) for vek in veky]
print(osmnact)
9 changes: 9 additions & 0 deletions doma2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nazvy = [
'Někdo to rád horké, extended edition',
'Adéla ještě nevečeřela',
'Kulový blesk'
]
delky = [136, 105, 82]

trvani = [f"{delka // 60}:{delka % 60}" for delka in delky]
print(trvani)
32 changes: 32 additions & 0 deletions doma3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
kraje = [
['Hlavní město Praha', '1 280 508'],
['Jihočeský kraj', '638 782'],
['Jihomoravský kraj', '1 178 812'],
['Karlovarský kraj', '296 749'],
['Kraj Vysočina', '508 952'],
['Královéhradecký kraj', '550 804'],
['Liberecký kraj', '440 636'],
['Moravskoslezský kraj', '1 209 879'],
['Olomoucký kraj', '633 925'],
['Pardubický kraj', '517 087'],
['Plzeňský kraj', '578 629'],
['Středočeský kraj', '1 338 982'],
['Ústecký kraj', '821 377'],
['Zlínský kraj', '583 698']
]

seznamy = [[kraj[0] for kraj in kraje], [int(kraj[-1].replace(" ", "")) for kraj in kraje]]
print(seznamy)
print()

pocty_obyvatel = [int(kraj[-1].replace(" ", "")) for kraj in kraje]
print(pocty_obyvatel)
print()

kraje = [kraj[0] for kraj in kraje]
print(kraje)
print()

dva_seznamy = kraje, pocty_obyvatel
print(dva_seznamy)
print()
34 changes: 34 additions & 0 deletions doma4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
hlasy = [
[78774, 43179, 225111, 144799, 242854],
[91062, 22451, 17475, 53391, 46450],
[179186, 216499, 4493, 156305, 61222],
[9619, 53476, 926, 64737, 34566],
[66904, 85730, 27271, 12964, 38041],
[118755, 1929, 30426, 25178, 31952],
[64467, 40993, 81181, 39392, 4335],
[11221, 97970, 26179, 98539, 112578],
[171064, 7638, 8752, 96666, 39738],
[74235, 101680, 18920, 45904, 1922],
[39309, 1505, 10531, 30458, 40228],
[131584, 1812, 241122, 22267, 99326],
[194133, 39985, 200997, 28229, 20780],
[66188, 51607, 15977, 177272, 17664]
]

# rezek = [hlas[0] for hlas in hlasy]
# dolezal = [hlas[1] for hlas in hlasy]
# bednar = [hlas[2] for hlas in hlasy]
# brotz = [hlas[3] for hlas in hlasy]
# kaspar = [hlas[4] for hlas in hlasy]
# print(sum(rezek), sum(dolezal), sum(bednar), sum(brotz), sum(kaspar))

hlasy_kandidatu = [sum(hlas) for hlas in zip(*hlasy)]
print(hlasy_kandidatu)

hlasy_kandidatu = [sum(hlas) for hlas in zip(*hlasy)]
print(max(hlasy_kandidatu))
print()

volebni_ucast = [sum(hlas) for hlas in hlasy]
print(volebni_ucast, max(volebni_ucast), min(volebni_ucast))

20 changes: 20 additions & 0 deletions doma5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
hlasy = [
[78774, 43179, 225111, 144799, 242854],
[91062, 22451, 17475, 53391, 46450],
[179186, 216499, 4493, 156305, 61222],
[9619, 53476, 926, 64737, 34566],
[66904, 85730, 27271, 12964, 38041],
[118755, 1929, 30426, 25178, 31952],
[64467, 40993, 81181, 39392, 4335],
[11221, 97970, 26179, 98539, 112578],
[171064, 7638, 8752, 96666, 39738],
[74235, 101680, 18920, 45904, 1922],
[39309, 1505, 10531, 30458, 40228],
[131584, 1812, 241122, 22267, 99326],
[194133, 39985, 200997, 28229, 20780],
[66188, 51607, 15977, 177272, 17664]
]

volebni_ucast = [max(hlas) for hlas in hlasy]
print(volebni_ucast)

35 changes: 35 additions & 0 deletions doma6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
hlasy = [
[78774, 43179, 225111, 144799, 242854],
[91062, 22451, 17475, 53391, 46450],
[179186, 216499, 4493, 156305, 61222],
[9619, 53476, 926, 64737, 34566],
[66904, 85730, 27271, 12964, 38041],
[118755, 1929, 30426, 25178, 31952],
[64467, 40993, 81181, 39392, 4335],
[11221, 97970, 26179, 98539, 112578],
[171064, 7638, 8752, 96666, 39738],
[74235, 101680, 18920, 45904, 1922],
[39309, 1505, 10531, 30458, 40228],
[131584, 1812, 241122, 22267, 99326],
[194133, 39985, 200997, 28229, 20780],
[66188, 51607, 15977, 177272, 17664]
]

prvni = [round((hlas/sum(hlasy[0]))*100, 2) for hlas in hlasy[0]]
druhy = [round((hlas/sum(hlasy[1]))*100, 2) for hlas in hlasy[1]]
treti = [round((hlas/sum(hlasy[2]))*100, 2) for hlas in hlasy[2]]
ctvrty = [round((hlas/sum(hlasy[3]))*100, 2) for hlas in hlasy[3]]
paty = [round((hlas/sum(hlasy[4]))*100, 2) for hlas in hlasy[4]]
sesty = [round((hlas/sum(hlasy[5]))*100, 2) for hlas in hlasy[5]]
sedmy = [round((hlas/sum(hlasy[6]))*100, 2) for hlas in hlasy[6]]
osmy = [round((hlas/sum(hlasy[7]))*100, 2) for hlas in hlasy[7]]
devaty = [round((hlas/sum(hlasy[8]))*100, 2) for hlas in hlasy[8]]
desaty = [round((hlas/sum(hlasy[9]))*100, 2) for hlas in hlasy[9]]
jedenacty = [round((hlas/sum(hlasy[10]))*100, 2) for hlas in hlasy[10]]
dvanacty = [round((hlas/sum(hlasy[11]))*100, 2) for hlas in hlasy[11]]
trinacty = [round((hlas/sum(hlasy[12]))*100, 2) for hlas in hlasy[12]]
ctrnacty = [round((hlas/sum(hlasy[13]))*100, 2) for hlas in hlasy[13]]

print(prvni, druhy, treti, ctvrty, paty, sesty, sedmy, osmy, devaty, desaty, jedenacty, dvanacty, trinacty, ctrnacty, sep="\n")


7 changes: 7 additions & 0 deletions had-velbloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys

def had_velbloud(parametr):
slova = parametr.split("_")
return slova[0] + "".join([slovo[0].upper() + slovo[1:] for slovo in slova[1:]])

print(had_velbloud(sys.argv[1]))
5 changes: 5 additions & 0 deletions hazeni_kostkou.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys
import random

print([random.randint(1, int(sys.argv[1])) for i in range(int(sys.argv[2]))])

3 changes: 3 additions & 0 deletions minuty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sys

print(int(sys.argv[1]) * 60 + int(sys.argv[2]))
5 changes: 5 additions & 0 deletions obraceni_slovniku.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def obrat_slovnik(slovnik):
return {hodnota: klic for klic, hodnota in slovnik.items()}

slovnik = {"pes": "dog", "kočka": "cat", "had": "snake"}
print(obrat_slovnik(slovnik))
13 changes: 13 additions & 0 deletions retezce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
jmena = ['Roman', 'Jan', 'Miroslav', 'Petr', 'Gabriel']

pocet_pismen = [len(jmeno) for jmeno in jmena]
print(pocet_pismen)

velka_pismena = [jmeno.upper() for jmeno in jmena]
print(velka_pismena)

plus_a = [jmeno + "a" for jmeno in jmena]
print(plus_a)

male_koncovka = [jmeno.lower() + "@email.cz" for jmeno in jmena]
print(male_koncovka)
23 changes: 23 additions & 0 deletions seznam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
teploty = [
[2.1, 5.2, 6.1, -0.1],
[2.2, 4.8, 5.6, -1.0],
[3.3, 6.5, 5.9, 1.2],
[2.9, 5.6, 6.0, 0.0],
[2.0, 4.6, 5.5, -1.2],
[1.0, 3.2, 2.1, -2.0],
[0.4, 2.7, 1.3, -2.8]
]

from statistics import mean
prumer = [mean(teplota) for teplota in teploty]
print(prumer)

ranni = [teplota[0] for teplota in teploty]
print(ranni)

nocni = [teplota[-1] for teplota in teploty]
print(nocni)

dvouprvkove = [teplota[-2:] for teplota in teploty]
print(dvouprvkove)

10 changes: 10 additions & 0 deletions ukol/doma1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
veky = [35, 12, 44, 11, 18, 21, 28, 18]

do_osmnacti = [int(18-vek) for vek in veky]
print(do_osmnacti)

plnoletost = [(vek >= 18) for vek in veky]
print(plnoletost)

osmnact = [(vek == 18) for vek in veky]
print(osmnact)
9 changes: 9 additions & 0 deletions ukol/doma2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nazvy = [
'Někdo to rád horké, extended edition',
'Adéla ještě nevečeřela',
'Kulový blesk'
]
delky = [136, 105, 82]

trvani = [f"{delka // 60}:{delka % 60}" for delka in delky]
print(trvani)
32 changes: 32 additions & 0 deletions ukol/doma3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
kraje = [
['Hlavní město Praha', '1 280 508'],
['Jihočeský kraj', '638 782'],
['Jihomoravský kraj', '1 178 812'],
['Karlovarský kraj', '296 749'],
['Kraj Vysočina', '508 952'],
['Královéhradecký kraj', '550 804'],
['Liberecký kraj', '440 636'],
['Moravskoslezský kraj', '1 209 879'],
['Olomoucký kraj', '633 925'],
['Pardubický kraj', '517 087'],
['Plzeňský kraj', '578 629'],
['Středočeský kraj', '1 338 982'],
['Ústecký kraj', '821 377'],
['Zlínský kraj', '583 698']
]

seznamy = [[kraj[0] for kraj in kraje], [int(kraj[-1].replace(" ", "")) for kraj in kraje]]
print(seznamy)
print()

pocty_obyvatel = [int(kraj[-1].replace(" ", "")) for kraj in kraje]
print(pocty_obyvatel)
print()

kraje = [kraj[0] for kraj in kraje]
print(kraje)
print()

dva_seznamy = kraje, pocty_obyvatel
print(dva_seznamy)
print()
34 changes: 34 additions & 0 deletions ukol/doma4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
hlasy = [
[78774, 43179, 225111, 144799, 242854],
[91062, 22451, 17475, 53391, 46450],
[179186, 216499, 4493, 156305, 61222],
[9619, 53476, 926, 64737, 34566],
[66904, 85730, 27271, 12964, 38041],
[118755, 1929, 30426, 25178, 31952],
[64467, 40993, 81181, 39392, 4335],
[11221, 97970, 26179, 98539, 112578],
[171064, 7638, 8752, 96666, 39738],
[74235, 101680, 18920, 45904, 1922],
[39309, 1505, 10531, 30458, 40228],
[131584, 1812, 241122, 22267, 99326],
[194133, 39985, 200997, 28229, 20780],
[66188, 51607, 15977, 177272, 17664]
]

# rezek = [hlas[0] for hlas in hlasy]
# dolezal = [hlas[1] for hlas in hlasy]
# bednar = [hlas[2] for hlas in hlasy]
# brotz = [hlas[3] for hlas in hlasy]
# kaspar = [hlas[4] for hlas in hlasy]
# print(sum(rezek), sum(dolezal), sum(bednar), sum(brotz), sum(kaspar))

hlasy_kandidatu = [sum(hlas) for hlas in zip(*hlasy)]
print(hlasy_kandidatu)

hlasy_kandidatu = [sum(hlas) for hlas in zip(*hlasy)]
print(max(hlasy_kandidatu))
print()

volebni_ucast = [sum(hlas) for hlas in hlasy]
print(volebni_ucast, max(volebni_ucast), min(volebni_ucast))

20 changes: 20 additions & 0 deletions ukol/doma5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
hlasy = [
[78774, 43179, 225111, 144799, 242854],
[91062, 22451, 17475, 53391, 46450],
[179186, 216499, 4493, 156305, 61222],
[9619, 53476, 926, 64737, 34566],
[66904, 85730, 27271, 12964, 38041],
[118755, 1929, 30426, 25178, 31952],
[64467, 40993, 81181, 39392, 4335],
[11221, 97970, 26179, 98539, 112578],
[171064, 7638, 8752, 96666, 39738],
[74235, 101680, 18920, 45904, 1922],
[39309, 1505, 10531, 30458, 40228],
[131584, 1812, 241122, 22267, 99326],
[194133, 39985, 200997, 28229, 20780],
[66188, 51607, 15977, 177272, 17664]
]

volebni_ucast = [max(hlas) for hlas in hlasy]
print(volebni_ucast)

35 changes: 35 additions & 0 deletions ukol/doma6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
hlasy = [
[78774, 43179, 225111, 144799, 242854],
[91062, 22451, 17475, 53391, 46450],
[179186, 216499, 4493, 156305, 61222],
[9619, 53476, 926, 64737, 34566],
[66904, 85730, 27271, 12964, 38041],
[118755, 1929, 30426, 25178, 31952],
[64467, 40993, 81181, 39392, 4335],
[11221, 97970, 26179, 98539, 112578],
[171064, 7638, 8752, 96666, 39738],
[74235, 101680, 18920, 45904, 1922],
[39309, 1505, 10531, 30458, 40228],
[131584, 1812, 241122, 22267, 99326],
[194133, 39985, 200997, 28229, 20780],
[66188, 51607, 15977, 177272, 17664]
]

prvni = [round((hlas/sum(hlasy[0]))*100, 2) for hlas in hlasy[0]]
druhy = [round((hlas/sum(hlasy[1]))*100, 2) for hlas in hlasy[1]]
treti = [round((hlas/sum(hlasy[2]))*100, 2) for hlas in hlasy[2]]
ctvrty = [round((hlas/sum(hlasy[3]))*100, 2) for hlas in hlasy[3]]
paty = [round((hlas/sum(hlasy[4]))*100, 2) for hlas in hlasy[4]]
sesty = [round((hlas/sum(hlasy[5]))*100, 2) for hlas in hlasy[5]]
sedmy = [round((hlas/sum(hlasy[6]))*100, 2) for hlas in hlasy[6]]
osmy = [round((hlas/sum(hlasy[7]))*100, 2) for hlas in hlasy[7]]
devaty = [round((hlas/sum(hlasy[8]))*100, 2) for hlas in hlasy[8]]
desaty = [round((hlas/sum(hlasy[9]))*100, 2) for hlas in hlasy[9]]
jedenacty = [round((hlas/sum(hlasy[10]))*100, 2) for hlas in hlasy[10]]
dvanacty = [round((hlas/sum(hlasy[11]))*100, 2) for hlas in hlasy[11]]
trinacty = [round((hlas/sum(hlasy[12]))*100, 2) for hlas in hlasy[12]]
ctrnacty = [round((hlas/sum(hlasy[13]))*100, 2) for hlas in hlasy[13]]

print(prvni, druhy, treti, ctvrty, paty, sesty, sedmy, osmy, devaty, desaty, jedenacty, dvanacty, trinacty, ctrnacty, sep="\n")


5 changes: 5 additions & 0 deletions ukol/obraceni_slovniku.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def obrat_slovnik(slovnik):
return {hodnota: klic for klic, hodnota in slovnik.items()}

slovnik = {"pes": "dog", "kočka": "cat", "had": "snake"}
print(obrat_slovnik(slovnik))
13 changes: 13 additions & 0 deletions ukol/retezce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
jmena = ['Roman', 'Jan', 'Miroslav', 'Petr', 'Gabriel']

pocet_pismen = [len(jmeno) for jmeno in jmena]
print(pocet_pismen)

velka_pismena = [jmeno.upper() for jmeno in jmena]
print(velka_pismena)

plus_a = [jmeno + "a" for jmeno in jmena]
print(plus_a)

male_koncovka = [jmeno.lower() + "@email.cz" for jmeno in jmena]
print(male_koncovka)
23 changes: 23 additions & 0 deletions ukol/seznam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
teploty = [
[2.1, 5.2, 6.1, -0.1],
[2.2, 4.8, 5.6, -1.0],
[3.3, 6.5, 5.9, 1.2],
[2.9, 5.6, 6.0, 0.0],
[2.0, 4.6, 5.5, -1.2],
[1.0, 3.2, 2.1, -2.0],
[0.4, 2.7, 1.3, -2.8]
]

from statistics import mean
prumer = [mean(teplota) for teplota in teploty]
print(prumer)

ranni = [teplota[0] for teplota in teploty]
print(ranni)

nocni = [teplota[-1] for teplota in teploty]
print(nocni)

dvouprvkove = [teplota[-2:] for teplota in teploty]
print(dvouprvkove)

Loading