-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
homework lesson 3 Fadeev #8
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def num_translate(num_dict: dict, num: str) -> str: | ||
"""Переводит числительное с английского на русский""" | ||
|
||
# str_out = num_dict[num] # В случае если искомого слова нет в словаре возвращает ошибку | ||
str_out = num_dict.get(num) | ||
return str_out | ||
|
||
|
||
# Словарь размещаем в теле программы, чтобы к нему могли обращаться другие функции | ||
user_dict = { | ||
'one': 'один', | ||
'two': 'два', | ||
'three': 'три', | ||
'four': 'четыре', | ||
'five': 'пять', | ||
'six': 'шесть', | ||
'seven': 'семь', | ||
'eight': 'восемь', | ||
'nine': 'девять', | ||
'ten': 'десять', | ||
'zero': 'нуль', | ||
} | ||
|
||
print(f'Перевод слова "two": {num_translate(user_dict, "two")}') | ||
print(f'Перевод слова "eight": {num_translate(user_dict, "eight")}') | ||
print(f'Перевод слова "eleven": {num_translate(user_dict, "eleven")}') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def thesaurus(*names: str) -> dict: | ||
|
||
key_list = [] | ||
aux_list = [] | ||
names_list = [] | ||
dictionary = {} | ||
|
||
# из входных аргументов получаем лист, состоящий из заглавных букв - key_list | ||
for i in range(0, len(names), 1): | ||
key_list.append(names[i][0]) | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. если уж завязались на такие манипуляции, то можно было посмотреть в сторону оптимизации через |
||
# удаляем повторы из листа key_list | ||
i = 0 | ||
while i < len(key_list) - 1: | ||
if key_list[i] == key_list[i + 1]: | ||
key_list.remove(key_list[i + 1]) | ||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. забыли метод |
||
else: | ||
i = i + 1 | ||
# по каждой букве из key_list формируем список из фамилий и добавляем его в список names_list, формируем словарь dictionary | ||
for i in range(0, len(key_list), 1): | ||
for k in range(0, len(names), 1): | ||
if key_list[i] == names[k][0]: | ||
aux_list.append(names[k]) | ||
names_list.append(aux_list) | ||
aux_list = [] | ||
dictionary.update({key_list[i]: names_list[i]}) | ||
|
||
return dictionary | ||
|
||
|
||
print(thesaurus("Виктор", "Владимир", "Борис", "Братислав", "Марина")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def get_jokes(count: int, flag: int) -> list: | ||
|
||
nouns = ["автомобиль", "лес", "огонь", "город", "дом"] | ||
adverbs = ["сегодня", "вчера", "завтра", "позавчера", "ночью"] | ||
adjectives = ["веселый", "яркий", "зеленый", "утопичный", "мягкий"] | ||
|
||
from random import randint | ||
|
||
joke_list = [] | ||
|
||
if flag == 0: | ||
for i in range(count): | ||
noun = nouns[randint(0, len(nouns) - 1)] | ||
adverb = adverbs[randint(0, len(adverbs) - 1)] | ||
adjective = adjectives[randint(0, len(adjectives) - 1)] | ||
joke_list.append(' '.join([noun, adverb, adjective])) | ||
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно было сделать в одну строку, используя |
||
i += 1 | ||
else: | ||
# для flag == 1 используется метод .pop() | ||
for i in range(0, len(nouns), 1): | ||
noun = nouns.pop(randint(0, len(nouns) - 1)) | ||
adverb = adverbs.pop(randint(0, len(adverbs) - 1)) | ||
adjective = adjectives.pop(randint(0, len(adjectives) - 1)) | ||
joke_list.append(' '.join([noun, adverb, adjective])) | ||
i += 1 | ||
|
||
return joke_list | ||
|
||
|
||
print(get_jokes(6, 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не нужно менять аргументы функции в исходном задании
value: str