-
Notifications
You must be signed in to change notification settings - Fork 467
commit with homework #170
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?
commit with homework #170
Changes from 2 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 |
|---|---|---|
|
|
@@ -21,7 +21,24 @@ def main(): | |
| Эта функция вызывается автоматически при запуске скрипта в консоли | ||
| В ней надо заменить pass на ваш код | ||
| """ | ||
| pass | ||
| product_sell = [ | ||
| {'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]}, | ||
| ] | ||
| total_sale = 0 | ||
|
|
||
| for i in range(len(product_sell)): | ||
| item = product_sell[i].get('product', 'no item') | ||
| sale = product_sell[i].get('items_sold', 0) | ||
|
|
||
| sum_of_sale = sum(sale) | ||
| average_sale = sum(sale) // len(sale) | ||
aka-nomad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| total_sale += sum_of_sale | ||
|
|
||
| print(f"{item}, Total amount of sale: {sum_of_sale}, Average number of sale:{average_sale}") | ||
|
|
||
| print(f"All items total sales: {total_sale}, All items average sales: {total_sale // len(product_sell)}") | ||
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,17 @@ def ask_user(answers_dict): | |
| """ | ||
| Замените pass на ваш код | ||
| """ | ||
| pass | ||
| dicts = { | ||
| "Как дела": "Хорошо!", "Что делаешь?": "Программирую", "Сколько тебе лет":"У меня нет возраста", "Любишь Питон":"Да" | ||
| } | ||
|
|
||
| while True: | ||
| answer = input("Задай свой вопрос:") | ||
|
||
| if answer in ("Пока", "пока"): | ||
| print("Пока!") | ||
| break | ||
| else: | ||
| print(f"Пользователь: {answer}{'\n'}Программа:{dicts.get(answer, 'У меня нет ответа на данный вопрос')}") | ||
aka-nomad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if __name__ == "__main__": | ||
| ask_user(questions_and_answers) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,11 +13,17 @@ | |
|
|
||
| """ | ||
|
|
||
| def discounted(price, discount, max_discount=20) | ||
| def discounted(price, discount, max_discount=20): | ||
| """ | ||
| Замените pass на ваш код | ||
| """ | ||
| pass | ||
| try: | ||
| price, discount, max_discount = float(price), float(discount), int(max_discount) | ||
| if max_discount >= 100: | ||
| raise ValueError('Слишком большая максимальная скидка') | ||
| return price - (price * discount / 100) | ||
| except (ValueError, TypeError): | ||
| print('Переданы некорректные аргументы или не сработало приведение типов данных!') | ||
|
||
|
|
||
| if __name__ == "__main__": | ||
| print(discounted(100, 2)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,23 +12,43 @@ | |
| бота отвечать, в каком созвездии сегодня находится планета. | ||
|
|
||
| """ | ||
| import logging | ||
| import logging, ephem, settings, datetime | ||
|
|
||
| from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | ||
|
|
||
| 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' | ||
| } | ||
| } | ||
| """ | ||
|
|
||
| def get_constellation(update, context): | ||
| try: | ||
| user_planet = update.message.text.split()[1].lower() | ||
|
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. Вот тут ты обрабатываешь исключение IndexError. Это хорошо И тут вижу приведение к нижнему регистру. Это хорошо
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. а я сделал исключение вот так: |
||
| current_date = datetime.datetime.now().strftime('%Y/%m/%d') | ||
| planets = { | ||
| 'mercury': ephem.Mercury(), 'venus':ephem.Venus(), 'mars':ephem.Mars(),'jupiter':ephem.Jupiter(), | ||
| 'saturn':ephem.Saturn(), 'uranus':ephem.Uranus(), 'neptun':ephem.Neptune() | ||
| } | ||
|
|
||
| if user_planet != '': | ||
| planet = planets.get(user_planet) | ||
| compute = planet.compute(current_date) | ||
| update.message.reply_text(ephem.constellation(planet)[1]) | ||
| except IndexError: | ||
| update.message.reply_text('ERROR! You do not determine the planet') | ||
|
|
||
| u = ephem.planet | ||
| print() | ||
| ephem.constellation | ||
|
|
||
| def greet_user(update, context): | ||
| text = 'Вызван /start' | ||
|
|
@@ -39,14 +59,15 @@ 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) | ||
|
|
||
|
|
||
| def main(): | ||
| mybot = Updater("КЛЮЧ, КОТОРЫЙ НАМ ВЫДАЛ BotFather", request_kwargs=PROXY, use_context=True) | ||
| mybot = Updater(settings.API_KEY) | ||
|
|
||
| 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() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| API_KEY = "7475700629:AAHvNdrcCzOdt2odHBippgfS7rFns1wAGQc" |
Uh oh!
There was an error while loading. Please reload this page.