-
-
Save hernikplays/355864bf476a317d4791f0b662549b10 to your computer and use it in GitHub Desktop.
Řetězce
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
retezec = input("Zadejte řetězec") | |
b = 0 | |
for p in retezec: | |
if(p.lower() == "b"): | |
b+=1 | |
print(f"Počet písmen 'b' je {b}") |
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
retezec = input("Zadejte řetězec") | |
s = "" | |
for p in retezec: | |
s+=p+p # duplikujeme | |
print(s) |
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
left = input("Zadejte první řetězec") | |
right = input("Zadejte druhý řetězec") | |
for i,p in enumerate(left): # enumerate způsobí že "i" je aktuální index a "p" je hodnota | |
if i<len(right) and p == right[i]: | |
print(f"Písmeno {p} je na stejné pozici v obou řetězcích ({i+1})") | |
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
text = input("Zadejte řetězec") | |
l = text.split(" ") # jednoduše splitneme na mezery | |
for s in l: | |
print(s[0]) #a vypíšeme první písmeno |
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
text = input("Zadejte řetězec") | |
v = "" | |
i = 0 | |
for p in text: | |
if i == 1: # jsme na sudém písmenu | |
i = 0 # přehodíme (šlo by použít i bool) | |
v+="X" # a přidáme x | |
elif p == " ": | |
v+=p # pokud je to mezera, jednoduše přidáme bez změny lichosti, aby se to stále pravidelně střídalo | |
else: # jinak přidáme písmeno | |
i=1 | |
v+=p | |
print(v) |
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
text = input("Zadejte řetězec") | |
v = "" | |
i = 0 | |
pul = len(text) // 2 # získáme polovinu, kdy máme začít na nový řádek | |
for e,p in enumerate(text): | |
print(e+2) | |
print(pul) | |
if p == " ": | |
v+=p | |
elif i == 1 and e == pul:# když jsme v sudé polovině, přidáme nový řádek (\n) s tečkou | |
v+="\n." | |
i = 0 | |
elif i == 0 and e == pul: # u lichého přidáme písmeno | |
v+="\n"+p | |
i = 1 | |
elif i == 1: | |
i = 0 | |
v+="." | |
else: | |
i=1 | |
v+=p | |
print(v) |
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
r = input("Zadejte vaše jméno a přijmení").split(" ") # rozdělíme rovnou | |
jmeno = r[0] | |
prijmeni = r[1] | |
print(f"Délka jména: {len(jmeno)}") # jednoduše vypíšeme (f je nový formátovací způsob v pythonu) | |
print(f"Délka přijmení: {len(prijmeni)}") | |
print(f"Iniciály: {jmeno[0].upper()}. {prijmeni[0].upper()}.") |
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
veta = input("Zadejte větu") | |
print(f"Počet slov: {len(veta.split(' '))}") # nejjednodušší je rozdělit a vypsat délku |
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
text = input("Zadejte text") | |
print(text.replace(" ","")) # jednoduše nahradíme pomocí replace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment