Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions 1_if1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

def main():
result = ''
age = abs(int(input('Введите возраст пользователя: ')))
age = int(input('Введите возраст пользователя: '))
if age < 0:
result = 'Возраст не может быть отрицательным'
if 65 > age >= 23:
result = 'Скорее всего пользователь работает'
elif 23 > age >= 18:
Expand All @@ -28,8 +30,8 @@ def main():
result = 'Скорее всего пользователь ходит в детский сад'
else:
result = 'Неизвестно что делает пользователь в этом возрасте'
return print(result)
return result


if __name__ == "__main__":
main()
print(main())
18 changes: 10 additions & 8 deletions 2_if2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@

"""


def main(first_str: str, second_str: str):
if type(first_str) is not str and type(second_str) is not str:
return print(0)
if not isinstance(first_str, str) and not isinstance(second_str, str):
return 0
elif first_str is not second_str and second_str == 'learn':
return print(3)
return 3
elif first_str is not second_str and len(first_str) > len(second_str):
return print(2)

return 2


if __name__ == "__main__":
main(1,2)
main('gun', 'gun')
main('easy', 'learn')
print(main(1,2))
print(main('gun', 'gun'))
print(main('easy', 'learn'))
4 changes: 2 additions & 2 deletions 3_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def school_average(school: list):
for list_of_scores in school:
result += (sum(list_of_scores['score']) / len(list_of_scores['score']))
result = result / len(school)
print('Average mark of school is:', '%.2f' % result)
print('Average mark of school is:', f'{result:.2f}')


def class_average(school: list):
result = 0
for list_of_scores in school:
result = sum(list_of_scores['score']) / len(list_of_scores['score'])
print('Average for class ', list_of_scores['school_class'], 'is:', '%.2f' % result)
print('Average for class ', list_of_scores['school_class'], 'is:', f'{result:.2f}')


def main(school: list):
Expand Down
5 changes: 3 additions & 2 deletions 5_while2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def ask_user(answers: dict):
console_input = ''
while console_input != 'Пока':
console_input = input('Введите вопрос: ')
if answers.get(console_input):
print(answers.get(console_input))
check_answers = answers.get(console_input)
if check_answers:
print(check_answers)
elif console_input != 'Пока':
print('Я затрудняюсь ответить на вопрос')

Expand Down
5 changes: 3 additions & 2 deletions 6_exception1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def ask_user(answers: dict):
while console_input != 'Пока':
try:
console_input = input('Введите вопрос: ')
if answers.get(console_input):
print(answers.get(console_input))
check_answers = answers.get(console_input)
if check_answers:
print(check_answers)
elif console_input != 'Пока':
print('Я затрудняюсь ответить на вопрос')
except KeyboardInterrupt:
Expand Down
6 changes: 3 additions & 3 deletions 7_exception2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
def get_summ(num_one, num_two):
try:
result = int(num_one) + int(num_two)
return result
except ValueError:
result = 'На вход функция может принимать только занчения типа int'
return result

return result


if __name__ == "__main__":
print(get_summ(2, 2))
print(get_summ(3, "3"))
Expand Down
30 changes: 14 additions & 16 deletions 8_ephem_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,24 @@ def talk_to_me(bot, update):


def find_planet_place(update, context):
planet_dict = {
'Mars': ephem.Mars,
'Jupiter': ephem.Jupiter,
'Mercury': ephem.Mercury,
'Venus': ephem.Venus,
'Saturn': ephem.Saturn,
'Uranus': ephem.Uranus,
'Neptune': ephem.Neptune,
}
dt_now = ephem.now()
get_planet = update.message.text.split()
if get_planet[1] == 'Mars':
planet_name = ephem.Mars(dt_now)
if get_planet[1] == 'Jupiter':
planet_name = ephem.Jupiter(dt_now)
if get_planet[1] == 'Mercury':
planet_name = ephem.Mercury(dt_now)
if get_planet[1] == 'Venus':
planet_name = ephem.Venus(dt_now)
if get_planet[1] == 'Saturn':
planet_name = ephem.Saturn(dt_now)
if get_planet[1] == 'Uranus':
planet_name = ephem.Uranus(dt_now)
if get_planet[1] == 'Neptune':
planet_name = ephem.Neptune(dt_now)
if planet_dict.get(get_planet[1]):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут вместо доступа по индексу лучше использовать распаковку

planet_name = planet_dict.get(get_planet[1])
planet_name = planet_name(dt_now)
planet_constellation = ephem.constellation(planet_name)
update.message.reply_text(planet_constellation[1])
else:
update.message.reply_text('Про этот объект я ничего не знаю')
planet_constellation = ephem.constellation(planet_name)
update.message.reply_text(planet_constellation[1])


def main():
Expand Down