added tasks
This commit is contained in:
parent
122c2c841e
commit
ef14ec8cd3
13
TaskC41/run.py
Normal file
13
TaskC41/run.py
Normal file
@ -0,0 +1,13 @@
|
||||
def is_valid_age(age):
|
||||
try:
|
||||
number, unit = age.split(" ")
|
||||
if unit == "lat" and number.isdigit():
|
||||
return 0 < int(number) <= 123
|
||||
return False
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
with open("test.in", "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
print("yes" if is_valid_age(line) else "no")
|
15
TaskC48/run.py
Normal file
15
TaskC48/run.py
Normal file
@ -0,0 +1,15 @@
|
||||
def is_alternating_case(string):
|
||||
if len(string) < 2:
|
||||
return False
|
||||
for i in range(len(string) - 1):
|
||||
if string[i].isalpha() and string[i + 1].isalpha():
|
||||
if string[i].islower() == string[i + 1].islower():
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
with open("test.in", "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
print("yes" if is_alternating_case(line) else "no")
|
16
TaskD00/run.py
Normal file
16
TaskD00/run.py
Normal file
@ -0,0 +1,16 @@
|
||||
def substitute_digits_to_chars(string):
|
||||
new_string = ""
|
||||
i = 0
|
||||
while i < len(string):
|
||||
if i + 4 <= len(string) and string[i:i+4].isdigit():
|
||||
new_string += ''.join(chr(ord('a') + int(digit)) for digit in string[i:i+4])
|
||||
i += 4
|
||||
else:
|
||||
new_string += string[i]
|
||||
i += 1
|
||||
return new_string
|
||||
|
||||
with open("simple.in", "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
print(substitute_digits_to_chars(line))
|
18
TaskD01/run.py
Normal file
18
TaskD01/run.py
Normal file
@ -0,0 +1,18 @@
|
||||
def swap_case(line):
|
||||
words = line.split()
|
||||
res = []
|
||||
for word in words:
|
||||
lower = any(c.islower() for c in word)
|
||||
upper = any(c.isupper() for c in word)
|
||||
|
||||
if lower and upper:
|
||||
res.append(word.swapcase())
|
||||
else:
|
||||
res.append(word)
|
||||
|
||||
return " ".join(res)
|
||||
|
||||
with open("simple.in", "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
print(swap_case(line))
|
11
TaskD02/run.py
Normal file
11
TaskD02/run.py
Normal file
@ -0,0 +1,11 @@
|
||||
def count_chars(line):
|
||||
lower = sum(c.islower() for c in line)
|
||||
upper = sum(c.isupper() for c in line)
|
||||
digit = sum(c.isdigit() for c in line)
|
||||
other = len(line) - (lower + upper + digit)
|
||||
return f"{lower} {upper} {digit} {other}"
|
||||
|
||||
with open("simple.in", "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
print(count_chars(line))
|
10
TaskD03/run.py
Normal file
10
TaskD03/run.py
Normal file
@ -0,0 +1,10 @@
|
||||
def count_words(line):
|
||||
words = line.split()
|
||||
lower = sum(1 for word in words if word and word[0].islower())
|
||||
upper = sum(1 for word in words if word and word[0].isupper())
|
||||
return f"{lower} {upper}"
|
||||
|
||||
with open("simple.in", "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
print(count_words(line))
|
18
TaskD04/run.py
Normal file
18
TaskD04/run.py
Normal file
@ -0,0 +1,18 @@
|
||||
def remove_second_number(line):
|
||||
words = line.split()
|
||||
count = 0
|
||||
result = []
|
||||
|
||||
for word in words:
|
||||
if word.isdigit():
|
||||
count += 1
|
||||
if count == 2:
|
||||
continue
|
||||
result.append(word)
|
||||
|
||||
return " ".join(result)
|
||||
with open("simple.in", "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
print(remove_second_number(line))
|
||||
|
Loading…
Reference in New Issue
Block a user