Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Напишите простую функцию, проверяющую, содержит ли строка слово «привет» на разных языках.
- # hello - english
- # ciao - italian
- # salut - french
- # hallo - german
- # hola - spanish
- # ahoj - czech republic
- # czesc – polish
- # Функция должна быть нечувствительна к регистру, чтобы пройти тесты
- def validate_hello(text):
- dict_hello = {
- 'hello': 'english',
- 'ciao': 'italian',
- 'salut': 'french',
- 'hallo': 'german',
- 'hola': 'spanish',
- 'ahoj': 'czech',
- 'republicczesc': 'polish'
- }
- list_words = text.lower().split()
- for word in list_words:
- if word in dict_hello.keys(): # Перебираем все ключи словаря
- return dict_hello[word] # Возвращаем значение по ключу
- print(validate_hello("World hola"))
- dict_hello = {
- 'hello': 'english',
- 'ciao': 'italian',
- 'salut': 'french',
- 'hallo': 'german',
- 'hola': 'spanish',
- 'ahoj': 'czech',
- 'republicczesc': 'polish'
- }
- # print(dict_hello["hola"])
- # print(dict_hello.get("привет"))
- # del dict_hello['republicczesc']
- # dict_hello['привет'] = 'Русский'
- # print(dict_hello.keys())
- # print(dict_hello.values())
- # print(dict_hello.items())
- product = {
- "Картошка": "200",
- "Капуста": "300",
- "Помидоры": "1000",
- }
- #
- # count = 1
- # for key, value in product.items():
- # print(f"{count}. {key}: {value}")
- # count += 1
- all_dict = product | dict_hello
- # print(all_dict)
- # Напишите функцию, которая принимает список строк и возвращает каждую строку
- # с правильным номером перед ним.
- # Нумерация начинается с 1. Формат n: строка. Обратите внимание
- # на двоеточие и пробел между ними.
- # Примеры: (Ввод --> Вывод)
- def number(line):
- for i in range(len(line)):
- line[i] = f"{i + 1}: {line[i]}"
- return line
- # ["a", "b", "c"] --> ["1: a", "2: b", "3: c"]
- print(number(["a", "b", "c"]))
- # Напишите функцию, которая вычисляет среднее значение чисел в заданном списке.
- # Примечание. Пустые массивы должны возвращать 0.
- # (1 + 2 + 3) / 3 = 2
- def average(numbers):
- return sum(numbers) // len(numbers)
- print(average([1, 2, 3]))
- # int - целое не дробное число
- # float - числа с плавающей точкой
- # bool - True False
- # str - строки в кавычках '' или ""
- # age_1 = 18
- # print(type(age_1))
- # age_1 = str(age_1)
- # print(type(age_1))
- # print()
- # age_2 = "18"
- # print(type(age_2))
- # age_2 = int(age_2)
- # print(type(age_2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement