Skip to content
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

ДЗ1 #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

ДЗ1 #125

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
20 changes: 19 additions & 1 deletion 1_if1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,30 @@

"""

def actyvity(age):
Copy link

Choose a reason for hiding this comment

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

опечатка, переменные и названия функций желательно на правильном английском языке писать

if age <= 6:
print("учиться в детском саду")
elif 6 < age <= 18:
print("учиться в школе")
elif 18 < age <= 24:
print("учиться в ВУЗе")
else:
print("работать")


def main():
"""
Эта функция вызывается автоматически при запуске скрипта в консоли
В ней надо заменить pass на ваш код
"""
pass
age_user = int(input("ввесте возраст "))

actyvity(age_user)





if __name__ == "__main__":
main()

26 changes: 23 additions & 3 deletions 2_if2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,27 @@ def main():
Эта функция вызывается автоматически при запуске скрипта в консоли
В ней надо заменить pass на ваш код
"""
pass


def check_is_strings(line_1, line_2):
if type(line_1) != str or type(line_2) != str:
return '0'
elif line_1 == line_2:
return '1'
elif line_1 != line_2 and len(line_1) > len(line_2):
return '2'
elif line_1 != line_2 and line_2 == 'learn':
return '3'

return 'не работает'

print(check_is_strings(1, 'kfdjgdgn')) # 0

print(check_is_strings('abra', 'abra')) # 1

print(check_is_strings('abra cadabra', 'abra')) # 2

print(check_is_strings('ccj', 'learn')) # 3


if __name__ == "__main__":
main()
main()
36 changes: 31 additions & 5 deletions 3_for.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""

Домашнее задание №1

Цикл for: Продажи товаров

* Дан список словарей с данными по колличеству проданных телефонов
[
{'product': 'iPhone 12', 'items_sold': [363, 500, 224, 358, 480, 476, 470, 216, 270, 388, 312, 186]},
Expand All @@ -15,13 +12,42 @@
* Посчитать и вывести суммарное количество продаж всех товаров
* Посчитать и вывести среднее количество продаж всех товаров
"""
from itertools import count, product


def main():
"""
Эта функция вызывается автоматически при запуске скрипта в консоли
В ней надо заменить pass на ваш код
"""
pass
phone = [
{'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]},
]

for i in range(len(phone)):
Copy link

Choose a reason for hiding this comment

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

здесь лучше использовать конструкцию enumerate for i, phone in enumerate(phone):

name = phone[i]['product']
summ = 0
for sale_one_model in phone [i] ['items_sold']:
Copy link

Choose a reason for hiding this comment

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

phone [i] ['items_sold'] - лишнии пробелы

summ = summ + sale_one_model
avg_score_model = summ / len(phone[i]['items_sold'])
print(f'суммарное количество продаж для {name}: {summ}')
print(f'среднее количество продаж для {name}: {avg_score_model}')

full_list = []
for i in range(len(phone)):
lists = phone[i]['items_sold']
for y in lists:
full_list.append(y)
print("суммарное количество продаж всех товаров:", sum(full_list))
print('среднее количество продаж всех товаров:', sum(full_list) / len(full_list))







if __name__ == "__main__":
main()
main()
12 changes: 5 additions & 7 deletions 4_while1.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
"""

Домашнее задание №1

Цикл while: hello_user

* Напишите функцию hello_user(), которая с помощью функции input() спрашивает
пользователя “Как дела?”, пока он не ответит “Хорошо”

"""


def hello_user():
"""
Замените pass на ваш код
"""
pass
while True:
user_say = input("Как дела? ")
if user_say == "Хорошо":
break



if __name__ == "__main__":
Expand Down
15 changes: 9 additions & 6 deletions 5_while2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

"""

questions_and_answers = {}
questions_and_answers = {"Как дела": "Хорошо!", "Что делаешь?": "Программирую", "где живешь": "в Липецке", "что ешь": "кашу", "на чем стоишь": "на мосту", "что пьешь": "квас"}

def ask_user(answers_dict):
"""
Замените pass на ваш код
"""
pass

answers = input("Задай вопрос ")
while answers not in questions_and_answers:
answers = input("Задай вопрос ")
while answers in questions_and_answers:
print(questions_and_answers[answers])
answers = input("Задай вопрос ")


if __name__ == "__main__":
ask_user(questions_and_answers)
11 changes: 7 additions & 4 deletions 6_exception1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
"""

def hello_user():
"""
Замените pass на ваш код
"""
pass
try:
while True:
user_say = input("Как дела? ")
if user_say == "Хорошо":
break
except KeyboardInterrupt:
print('Пока')

if __name__ == "__main__":
hello_user()
17 changes: 15 additions & 2 deletions 7_exception2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@

"""

def discounted(price, discount, max_discount=20)
def discounted(price, discount, max_discount=20):
"""
Замените pass на ваш код
"""
pass
try:
price = abs(float(price))
discount = abs(float(discount))
max_discount = abs(int(max_discount))
if max_discount >= 100:
raise ValueError('Слишком большая максимальная скидка')
if discount >= max_discount:
return price
else:
return price - (price * discount / 100)
except ValueError:
return'Требуется ввести числа'
except TypeError:
return 'Не тот тип данных'

if __name__ == "__main__":
print(discounted(100, 2))
Expand Down