diff --git a/lesson_3/3-1.py b/lesson_3/3-1.py new file mode 100644 index 0000000..a998385 --- /dev/null +++ b/lesson_3/3-1.py @@ -0,0 +1,11 @@ +def my_func(arg1, arg2): + try: + result = arg1 / arg2 + return result + except ZeroDivisionError: + return "На ноль делить нельзя" + + +first_num = float(input("Введите первое число: ")) +second_num = float(input("Введите второе число: ")) +print(my_func(first_num, second_num)) diff --git a/lesson_3/3-2.py b/lesson_3/3-2.py new file mode 100644 index 0000000..1231806 --- /dev/null +++ b/lesson_3/3-2.py @@ -0,0 +1,7 @@ +def my_func(f_name, f_name2, f_year, f_city, f_email, f_phone): + print(f"Меня зовут {f_name} {f_name2}, я родился в {f_year} году, в городе {f_city}. " + f"Мой эл. адрес {f_email}, телефон {f_phone}") + + +my_func(f_name="Иван", f_name2="Павлов", f_year="1990", + f_city="Городец", f_email="ivan@mail.ru", f_phone="+7123456789") diff --git a/lesson_3/3-3.py b/lesson_3/3-3.py new file mode 100644 index 0000000..8c010fd --- /dev/null +++ b/lesson_3/3-3.py @@ -0,0 +1,5 @@ +def my_func(f_one, f_two, f_three): + print(f_one + f_two + f_three - min(f_one, f_two, f_three)) + + +my_func(70, 50, 80) diff --git a/lesson_3/3-4.py b/lesson_3/3-4.py new file mode 100644 index 0000000..6541ab7 --- /dev/null +++ b/lesson_3/3-4.py @@ -0,0 +1,31 @@ +# Оператор ** +def my_func(x, y): + if y >= 0: + print("Введите целое отрицательное число. Выход из программы.") + exit() + return x ** y + + +a = float(input("Основание. Введите число больше нуля: ")) +b = int(input("Степень. Введите целое отрицательное число: ")) +print(my_func(a, b)) + + +# Цикл while +def my_func(x, y): + y = abs(y) + i = 1 + c = int() + while i <= y - 1: + if i > 1: + c = c * x + else: + c = x * x + if i == (y - 1): + return 1 / c + i += 1 + + +a = float(input("Основание. Введите число больше нуля: ")) +b = int(input("Степень. Введите целое отрицательное число: ")) +print(my_func(a, b)) diff --git a/lesson_3/3-5.py b/lesson_3/3-5.py new file mode 100644 index 0000000..30a486f --- /dev/null +++ b/lesson_3/3-5.py @@ -0,0 +1,17 @@ +def my_sum(): + sum_result = 0 + ex = False + while ex == False: + number = input('Введите числа через пробел, для выхода нажмите Q: ').split() + result = 0 + for i in range(len(number)): + if number[i] == 'q' or number[i] == 'Q': + ex = True + return sum_result + else: + result = result + int(number[i]) + sum_result = sum_result + result + print(f'Сумма чисел равна: {sum_result}') + + +my_sum() diff --git a/lesson_3/3-6.py b/lesson_3/3-6.py new file mode 100644 index 0000000..ea21889 --- /dev/null +++ b/lesson_3/3-6.py @@ -0,0 +1,22 @@ +# Первый вариант +def func(a): + return a.title() + + +print(func("hello world")) + + +# Второй вариант + +def int_func(a): + separate_word = a.split(' ') + total = [] + for i in separate_word: + string_element = str(i) + first_letter = string_element[:1].upper() + word = first_letter + string_element[1:] + total.append(word) + return total + + +print(int_func("hello world"))