Advertisement
SomeBody_Aplle

Untitled

Jun 20th, 2023
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. # Напишите простую функцию, проверяющую, содержит ли строка слово «привет» на разных языках.
  2. # hello - english
  3. # ciao - italian
  4. # salut - french
  5. # hallo - german
  6. # hola - spanish
  7. # ahoj - czech republic
  8. # czesc – polish
  9. # Функция должна быть нечувствительна к регистру, чтобы пройти тесты
  10.  
  11. def validate_hello(text):
  12. dict_hello = {
  13. 'hello': 'english',
  14. 'ciao': 'italian',
  15. 'salut': 'french',
  16. 'hallo': 'german',
  17. 'hola': 'spanish',
  18. 'ahoj': 'czech',
  19. 'republicczesc': 'polish'
  20. }
  21. list_words = text.lower().split()
  22. for word in list_words:
  23. if word in dict_hello.keys(): # Перебираем все ключи словаря
  24. return dict_hello[word] # Возвращаем значение по ключу
  25.  
  26.  
  27. print(validate_hello("World hola"))
  28.  
  29. dict_hello = {
  30. 'hello': 'english',
  31. 'ciao': 'italian',
  32. 'salut': 'french',
  33. 'hallo': 'german',
  34. 'hola': 'spanish',
  35. 'ahoj': 'czech',
  36. 'republicczesc': 'polish'
  37. }
  38.  
  39. # print(dict_hello["hola"])
  40. # print(dict_hello.get("привет"))
  41. # del dict_hello['republicczesc']
  42. # dict_hello['привет'] = 'Русский'
  43.  
  44. # print(dict_hello.keys())
  45. # print(dict_hello.values())
  46. # print(dict_hello.items())
  47.  
  48. product = {
  49. "Картошка": "200",
  50. "Капуста": "300",
  51. "Помидоры": "1000",
  52. }
  53. #
  54. # count = 1
  55. # for key, value in product.items():
  56. # print(f"{count}. {key}: {value}")
  57. # count += 1
  58.  
  59. all_dict = product | dict_hello
  60.  
  61.  
  62. # print(all_dict)
  63.  
  64.  
  65. # Напишите функцию, которая принимает список строк и возвращает каждую строку
  66. # с правильным номером перед ним.
  67. # Нумерация начинается с 1. Формат n: строка. Обратите внимание
  68. # на двоеточие и пробел между ними.
  69. # Примеры: (Ввод --> Вывод)
  70.  
  71. def number(line):
  72. for i in range(len(line)):
  73. line[i] = f"{i + 1}: {line[i]}"
  74. return line
  75.  
  76.  
  77. # ["a", "b", "c"] --> ["1: a", "2: b", "3: c"]
  78. print(number(["a", "b", "c"]))
  79.  
  80. # Напишите функцию, которая вычисляет среднее значение чисел в заданном списке.
  81. # Примечание. Пустые массивы должны возвращать 0.
  82. # (1 + 2 + 3) / 3 = 2
  83.  
  84. def average(numbers):
  85. return sum(numbers) // len(numbers)
  86.  
  87.  
  88. print(average([1, 2, 3]))
  89.  
  90. # int - целое не дробное число
  91. # float - числа с плавающей точкой
  92. # bool - True False
  93. # str - строки в кавычках '' или ""
  94.  
  95. # age_1 = 18
  96. # print(type(age_1))
  97. # age_1 = str(age_1)
  98. # print(type(age_1))
  99. # print()
  100. # age_2 = "18"
  101. # print(type(age_2))
  102. # age_2 = int(age_2)
  103. # print(type(age_2))
  104.  
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement