-
Notifications
You must be signed in to change notification settings - Fork 73
Practical work 3 Pogorely_E_P #133
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 7 commits
16d6e67
3a32f48
babb021
13f9556
cd586db
cac1425
4124c0e
98980b1
b173d00
55b912b
203d39f
6ffa361
8c7f74d
fa4a73c
1a74dae
56a112e
6a15565
37852ee
d984c17
f3ee376
307bea5
7563fec
77f1868
fa49010
f03e726
91c4d1c
b0f4953
03dbe20
2459f00
6ec341a
13490ad
cd6e9b0
52539fd
af888a8
e4812f6
9a605ab
661408b
44cdd5e
3a69e72
b0efbf8
bff2bd0
0c8864b
10e0d38
92e5ee1
815dbcd
6ea7028
92f8ea5
88c059b
17e9197
a903767
8c09661
146cfe4
6c65765
f729457
1ddac2a
31e3768
4bd25a9
ec9cefd
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 1. Реализовать функцию, принимающую два числа (позиционные аргументы) | ||
| # и выполняющую их деление. Числа запрашивать у пользователя, предусмотреть | ||
| # обработку ситуации деления на ноль. | ||
|
|
||
| def div(x, y): | ||
| res: int | ||
| error: str = 'Вы ввели не корректные числа.' | ||
| if x > 0 and y >0: | ||
| res = x/y | ||
| return res | ||
| else: | ||
| return error | ||
| var_input_first = int(input('Введите первое число: ')) | ||
| var_input_second = int(input('Введите второе число: ')) | ||
|
|
||
| print(div(var_input_first, var_input_second)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # 2. Выполнить функцию, которая принимает несколько параметров, описывающих | ||
| # данные пользователя: имя, фамилия, год рождения, город проживания, email, | ||
| # телефон. Функция должна принимать параметры как именованные аргументы. | ||
| # Осуществить вывод данных о пользователе одной строкой. | ||
|
|
||
| def person(name, sec_name, age, city, email, tel): | ||
| return f'Имя - {name}, фамилия - {sec_name}, год рождения - {age}, город проживания - {city}, ' \ | ||
| f'email - {email}, телефон {tel}' | ||
|
|
||
|
|
||
| name = input('Введите имя: ') | ||
| sec_name = input('Введите Фамилию: ') | ||
| age = input('Введите год рождения: ') | ||
| city = input('Введите город проживания: ') | ||
| email = input('Введите email:') | ||
| tel = input('Введите телефон: ') | ||
|
|
||
| print(person(name, sec_name, age, city, email, tel)) | ||
|
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. не выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # 3. Реализовать функцию my_func(), которая принимает три позиционных | ||
| # аргумента и возвращает сумму наибольших двух аргументов. | ||
|
|
||
| def my_func(a, b, c): | ||
| sum: int | ||
| if a > b > c: | ||
| return a + b | ||
| elif a > c > b: | ||
| return a + c | ||
| elif b > c > a: | ||
| return b + c | ||
| elif c > b > a: | ||
| return c + b | ||
|
|
||
|
|
||
|
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: int |
||
| a = int(input('Введите первое число: ')) | ||
| b = int(input('Введите второе число: ')) | ||
| c = int(input('Введите третье число: ')) | ||
|
|
||
| print(my_func(a, b, c)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # 4. Программа принимает действительное положительное число x и целое | ||
| # отрицательное число y. Выполните возведение числа x в степень y. | ||
| # Задание реализуйте в виде функции my_func(x, y). При решении задания | ||
| # нужно обойтись без встроенной функции возведения числа в степень. | ||
| # Подсказка: попробуйте решить задачу двумя способами. | ||
| # Первый — возведение в степень с помощью оператора **. | ||
| # Второй — более сложная реализация без оператора **, предусматривающая | ||
| # использование цикла. | ||
|
|
||
| def my_func(x, y): | ||
| res = x ** y | ||
| return res | ||
| def my_func_cicle(x, y): | ||
| tmp = x | ||
| for i in range(1, y*(-1)): | ||
| tmp *= x | ||
| res = 1/tmp | ||
| return res | ||
|
|
||
|
|
||
| x = float(input('Введите действительное положительное число: ')) | ||
| y = int(input('Введите целое отрицательное число: ')) | ||
|
|
||
| print(f'Ответ с использывание встроеной функции {my_func(x, y)}') | ||
| print(f'Ответ с использованием цикла {my_func_cicle(x, y)}') | ||
|
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. выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 5. Программа запрашивает у пользователя строку чисел, разделённых пробелом. | ||
| # При нажатии Enter должна выводиться сумма чисел. Пользователь может | ||
| # продолжить ввод чисел, разделённых пробелом и снова нажать Enter. | ||
| # Сумма вновь введённых чисел будет добавляться к уже подсчитанной сумме. | ||
| # Но если вместо числа вводится специальный символ, выполнение программы | ||
| # завершается. Если специальный символ введён после нескольких чисел, | ||
| # то вначале нужно добавить сумму этих чисел к полученной ранее сумме и | ||
| # после этого завершить программу. | ||
|
|
||
| def sum_input(s_input): | ||
| ls = list(map(int, s_input.split(' '))) | ||
| return sum(ls) | ||
|
|
||
|
|
||
| ex = False | ||
| res = 0 | ||
| while not ex: | ||
| user_input = input('Введите строку чисел раделенных пробелом(для выхода введите q): ') | ||
| if user_input == 'q': | ||
| ex = True | ||
| else: | ||
| res += sum_input(user_input) | ||
| print(res) | ||
|
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. выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # 6. Реализовать функцию int_func(), принимающую слова из маленьких латинских | ||
| # букв и возвращающую их же, но с прописной первой буквой. | ||
| # Например, print(int_func(‘text’)) -> Text. | ||
|
|
||
| def int_func(s): | ||
| return s.capitalize() | ||
|
|
||
|
|
||
| input_string = input('Введите слово латинскими буквами в нижнем регистре: ') | ||
|
|
||
| print(int_func(input_string)) | ||
|
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. выполнено |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # 7. Продолжить работу над заданием. В программу должна попадать строка из слов, | ||
| # разделённых пробелом. Каждое слово состоит из латинских букв в нижнем регистре. | ||
| # Нужно сделать вывод исходной строки, но каждое слово должно начинаться с | ||
| # заглавной буквы. Используйте написанную ранее функцию int_func(). | ||
|
|
||
| def int_func(s): | ||
| res = '' | ||
| ls = list(map(str, s.split(' '))) | ||
| for i in ls: | ||
| res += ' ' + i.capitalize() | ||
| return res | ||
|
|
||
|
|
||
| input_string = input('Введите слово латинскими буквами в нижнем регистре: ') | ||
| print(int_func(input_string)) | ||
|
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. выполнено |
||
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.
res = x/y
проверьте все листинги на пеп-8