Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. Гласные и согласные
- def count_vowels_consonants(s):
- s = s.lower()
- vowels = set("аеёиоуыэюя")
- consonants = set("бвгджзйклмнпрстфхцчшщ")
- v_count = sum(1 for ch in s if ch in vowels)
- c_count = sum(1 for ch in s if ch in consonants)
- print("Гласных:", v_count, "Согласных:", c_count)
- # 2. Имя из e‑mail
- def extract_username(email):
- if "@" not in email:
- print("Ошибка: нет символа @")
- else:
- print(email.split("@", 1)[0])
- # 3. Нормализация пробелов
- def normalize_spaces(s):
- parts = s.split()
- result = " ".join(parts)
- print(result)
- # 4. Палиндром
- import re
- def is_palindrome(phrase):
- cleaned = re.sub(r'[^A-Za-zА-Яа-я0-9]', '', phrase).lower()
- print(cleaned == cleaned[::-1])
- # 5. Шифр Цезаря (русский алфавит)
- def caesar_rus(text, k):
- alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
- def shift(ch):
- lower = ch.lower()
- if lower in alpha:
- i = alpha.index(lower)
- new = alpha[(i + k) % len(alpha)]
- return new.upper() if ch.isupper() else new
- return ch
- print("".join(shift(ch) for ch in text))
- # 6. Проверка пароля
- def check_password(pwd):
- ok = True
- if len(pwd) < 8:
- print("Пароль слишком короткий")
- ok = False
- if not any(ch.isdigit() for ch in pwd):
- print("Нет цифр")
- ok = False
- if not any(ch.islower() for ch in pwd):
- print("Нет строчных букв")
- ok = False
- if not any(ch.isupper() for ch in pwd):
- print("Нет заглавных букв")
- ok = False
- if ok:
- print("Пароль надёжен")
- # 7. Формат даты
- def reformat_date(dt):
- parts = dt.split(".")
- if len(parts) != 3 or not all(p.isdigit() for p in parts):
- print("Некорректный ввод")
- else:
- d, m, y = parts
- if len(d)==2 and len(m)==2 and len(y)==4:
- print(f"{y}-{m}-{d}")
- else:
- print("Некорректный ввод")
- # 8. Аббревиатура ФИО
- def abbrev_fio(fio):
- parts = fio.split()
- if len(parts)==3:
- last, first, patron = parts
- print(f"{last} {first[0]}.{patron[0]}.")
- else:
- print("Неверный формат ФИО")
- # 9. Частотный анализ
- import string
- def top3_words(text):
- text = text.lower()
- for p in string.punctuation:
- text = text.replace(p, " ")
- words = [w for w in text.split() if w]
- from collections import Counter
- cnt = Counter(words)
- for word, _ in cnt.most_common(3):
- print(word)
- # 10. Парсер параметров URL
- def parse_url_params(url):
- if "?" not in url:
- print("Нет параметров")
- return
- qs = url.split("?",1)[1]
- pairs = qs.split("&")
- for pair in pairs:
- if "=" in pair:
- k, v = pair.split("=",1)
- print(f"{k}:{v}")
- else:
- print(f"{pair}:")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement