-
Notifications
You must be signed in to change notification settings - Fork 467
Первые два задания на проверку #138
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
base: master
Are you sure you want to change the base?
Changes from all commits
73f530d
2135b82
ecac4dc
81cea11
106b4cc
c4f7a70
fdbd696
1a133ae
05ed68d
a6e9a6a
4d6f8c8
79209f9
a1c78dc
6b30a1d
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 |
|---|---|---|
|
|
@@ -121,3 +121,6 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # Settings | ||
| settings.py | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,41 @@ | |
| * Посчитать и вывести среднее количество продаж всех товаров | ||
| """ | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| Эта функция вызывается автоматически при запуске скрипта в консоли | ||
| В ней надо заменить pass на ваш код | ||
| """ | ||
| pass | ||
|
|
||
|
|
||
| phones = [ | ||
| {'product': 'iPhone 12', 'items_sold': [ | ||
| 363, 500, 224, 358, 480, 476, 470, 216, 270, 388, 312, 186]}, | ||
| {'product': 'Xiaomi Mi11', 'items_sold': [ | ||
| 317, 267, 290, 431, 211, 354, 276, 526, 141, 453, 510, 316]}, | ||
| {'product': 'Samsung Galaxy 21', 'items_sold': [ | ||
| 343, 390, 238, 437, 214, 494, 441, 518, 212, 288, 272, 247]}, | ||
| ] | ||
|
|
||
| def count_sum(items_list): | ||
|
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. здорово что написал сам! Дальше можно использовать встроенную функцию sum |
||
| items_sum = 0 | ||
| for item in items_list: | ||
| items_sum += item | ||
| return items_sum | ||
|
|
||
| phones_sum = 0 | ||
| for phone in phones: | ||
| phone['sum_sold'] = count_sum(phone['items_sold']) | ||
| phone_sold_avg = int(phone['sum_sold'] / len(phone['items_sold'])) | ||
| phones_sum += phone['sum_sold'] | ||
| print( | ||
| f"Суммарный объем продаж {phone['product']}: {phone['sum_sold']}") | ||
| print( | ||
| f"Средний объем продаж {phone['product']}: {phone_sold_avg}", end='\n\n') | ||
| print(f"Всего телефонов продано: {phones_sum}") | ||
| phones_avg = int(phones_sum / len(phones)) | ||
| print(f"В среднем телефонов продано: {phones_avg}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,10 @@ def hello_user(): | |
| """ | ||
| Замените pass на ваш код | ||
| """ | ||
| pass | ||
| while True: | ||
| if input('Как дела? \n') == 'Хорошо': | ||
| break | ||
|
|
||
|
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. 👍 |
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| hello_user() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,22 @@ | |
| """ | ||
|
|
||
| questions_and_answers = {} | ||
| questions_and_answers = { | ||
| 'Как дела': 'Хорошо!', | ||
| 'Что делаешь': 'Программирую', | ||
| 'И все?': 'Ну, почти', | ||
| 'Ну и лошара': 'Да пошел ты' | ||
| } | ||
|
|
||
| def ask_user(answers_dict): | ||
| """ | ||
| Замените pass на ваш код | ||
| """ | ||
| pass | ||
| print('Введите вопрос: ') | ||
| while True: | ||
| question = input('Пользователь: ') | ||
| if answers_dict.get(question): | ||
| print(f"Программа: {answers_dict.get(question, '')}", end='\n\n') | ||
|
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. 👍 Отлично! Не придраться |
||
|
|
||
| if __name__ == "__main__": | ||
| ask_user(questions_and_answers) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,20 +14,22 @@ | |
| """ | ||
| import logging | ||
|
|
||
| import ephem, pprint | ||
| from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | ||
| import settings | ||
|
|
||
| logging.basicConfig(format='%(name)s - %(levelname)s - %(message)s', | ||
| level=logging.INFO, | ||
| filename='bot.log') | ||
|
|
||
|
|
||
| PROXY = { | ||
| 'proxy_url': 'socks5://t1.learn.python.ru:1080', | ||
| 'urllib3_proxy_kwargs': { | ||
| 'username': 'learn', | ||
| 'password': 'python' | ||
| } | ||
| } | ||
| # PROXY = { | ||
| # 'proxy_url': 'socks5://t1.learn.python.ru:1080', | ||
| # 'urllib3_proxy_kwargs': { | ||
| # 'username': 'learn', | ||
| # 'password': 'python' | ||
| # } | ||
| # } | ||
|
|
||
|
|
||
| def greet_user(update, context): | ||
|
|
@@ -39,14 +41,45 @@ def greet_user(update, context): | |
| def talk_to_me(update, context): | ||
| user_text = update.message.text | ||
| print(user_text) | ||
| update.message.reply_text(text) | ||
| update.message.reply_text(user_text) | ||
|
|
||
| planet_name = { | ||
| 'Mercury': ephem.Mercury(), | ||
| 'Venus': ephem.Venus(), | ||
| 'Mars': ephem.Mars(), | ||
| 'Jupiter': ephem.Jupiter(), | ||
| 'Saturn': ephem.Saturn(), | ||
| 'Uranus': ephem.Uranus(), | ||
| 'Neptune': ephem.Neptune(), | ||
| 'Pluto': ephem.Pluto() | ||
| } | ||
|
|
||
| def get_constellation(update, context): | ||
| user_input = context.args[0].capitalize() | ||
|
|
||
| try: | ||
| planet_name[user_input] | ||
| except KeyError: | ||
| if user_input == 'Earth': | ||
| update.message.reply_text('Earth is not in any constellation') | ||
| else: | ||
| update.message.reply_text(f'{user_input} is not a planet of solar system') | ||
|
|
||
| planet_name[user_input].compute() | ||
|
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. А ты тестировал свою программу с неправильными планетами? Мне кажется что надо проверить ;)
Author
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. |
||
| constellation_name = ephem.constellation(planet_name[user_input])[1] | ||
| # print(constellation_name, constellation_name[1]) | ||
| # constellation_name = update.message.text.split() | ||
| print(f'{planet_name[user_input].name} is currently in the constellation of {constellation_name}') | ||
| update.message.reply_text(f'{planet_name[user_input].name} is currently in the constellation of {constellation_name}') | ||
|
|
||
|
|
||
|
|
||
| def main(): | ||
| mybot = Updater("КЛЮЧ, КОТОРЫЙ НАМ ВЫДАЛ BotFather", request_kwargs=PROXY, use_context=True) | ||
| mybot = Updater(settings.API_KEY, use_context=True) | ||
|
|
||
| dp = mybot.dispatcher | ||
| dp.add_handler(CommandHandler("start", greet_user)) | ||
| dp.add_handler(CommandHandler("planet", get_constellation)) | ||
| dp.add_handler(MessageHandler(Filters.text, talk_to_me)) | ||
|
|
||
| mybot.start_polling() | ||
|
|
||

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.
А можешь придумать тест из 2 строк, в котором выведется на экран что-то кроме 0-1-2-3
Это очень полезное упражнение :)
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.
4d6f8c8 Приделал, сразу потребовался else :)