-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson02 #2
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?
Lesson02 #2
Changes from all 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #Задание №1 | ||
| # Написать программу, которая будет складывать, вычитать, умножать или делить два числа. | ||
| # Числа и знак операции вводятся пользователем. После выполнения вычисления | ||
| # программа не завершается, а запрашивает новые данные для вычислений. | ||
| # Завершение программы должно выполняться при вводе символа '0' в качестве знака | ||
| # операции. Если пользователь вводит неверный знак (не '0', '+', '-', '*', '/'), | ||
| # программа должна сообщать об ошибке и снова запрашивать знак операции. Также она | ||
| # должна сообщать пользователю о невозможности деления на ноль, если он ввел его в | ||
| # качестве делителя. | ||
|
|
||
| while True: | ||
| x1 = int(input("Ведите первое число:")); | ||
| x2 = int(input("Ведите второе число:")); | ||
| znak = input("Ведите знак операции +,-,*,/\nЛибо введите 0 для выхода:"); | ||
| if znak == "+": | ||
| res = x1 + x2; | ||
| elif znak == "-": | ||
| res = x1 - x2; | ||
| elif znak == "*": | ||
| res = x1 * x2; | ||
| elif znak == "/": | ||
| if x2 == 0: | ||
| print("Делитель не может равен 0"); | ||
| continue; | ||
| else: | ||
| res = x1 / x2; | ||
| elif znak == "0": | ||
| break; | ||
| else: | ||
| print("Веден неверный знак операции."); | ||
| continue; | ||
| print(res); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #Задание №2 | ||
| # Посчитать четные и нечетные цифры введенного натурального числа. Например, если | ||
| # введено число 34560, в нем 3 четные цифры (4, 6 и 0) и 2 нечетные (3 и 5). | ||
|
|
||
|
|
||
| def chet_ne_chet(x): | ||
| global chet | ||
|
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. По блок-схеме видно, что автор активно думал о реализации на Python, когда рисовал. Даже глобальные переменные нарисовал. |
||
| global ne_chet | ||
| cur_chislo = x % 10 | ||
| cur_ostatok = x // 10 | ||
| if (cur_chislo % 2) == 0: | ||
| chet += 1; | ||
| else: | ||
| ne_chet += 1; | ||
| if cur_ostatok == 0: | ||
| return | ||
| chet_ne_chet(cur_ostatok) | ||
|
|
||
|
|
||
| chet = ne_chet = 0; | ||
|
|
||
| x = int(input("Введите натуральное число")); | ||
| chet_ne_chet(x) | ||
| print("Количество четных цифр:", chet); | ||
| print("Количество нечетных цифр:", ne_chet); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #Задание №3 | ||
| # Сформировать из введенного числа обратное по порядку входящих в него цифр | ||
| # и вывести на экран. Например, если введено число 3486, надо вывести 6843. | ||
|
|
||
| def Reverse(x): | ||
|
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. Авторский стиль в каждой работе. Что ж, принимается :-))) |
||
| global Rev; | ||
| cur_chislo = x % 10; | ||
| cur_ostatok = x // 10; | ||
| Rev = Rev*10+cur_chislo | ||
| if cur_ostatok == 0: | ||
| return cur_chislo | ||
| else: | ||
| Reverse(cur_ostatok); | ||
|
|
||
|
|
||
| x = int(input("Введите натуральное число")); | ||
| Rev = 0; | ||
| Reverse(x); | ||
| print(Rev); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #Задание #4 | ||
| # Найти сумму n элементов следующего ряда чисел: 1, -0.5, 0.25, -0.125,… Количество | ||
| # элементов (n) вводится с клавиатуры. | ||
|
|
||
| def element(r,k): | ||
| if k == 0: | ||
| return r | ||
| else: | ||
| r = r / 2 | ||
| if r % 2 != 0: | ||
| r = r * (-1) | ||
| return(element(r,k-1)) | ||
|
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. А судя по блок-схеме перед return нужен else. |
||
|
|
||
|
|
||
| s = 0 | ||
| n = int(input("Введите значение n")); | ||
| for i in range(n): | ||
| s += element(1,i) | ||
| print(s) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Задание №5 | ||
| # Вывести на экран коды и символы таблицы ASCII, начиная с символа под номером 32 | ||
| # и заканчивая 127-м включительно. Вывод выполнить в табличной форме: по десять | ||
| # пар "код-символ" в каждой строке. | ||
|
|
||
| count = 0 | ||
| r = "" | ||
| size_col = 6 | ||
| start_ = 32 | ||
| end_ = 127 | ||
| for i in range(start_,end_+1): | ||
|
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.
|
||
| count += 1; | ||
| para = chr(i) + ":" + str(i) | ||
| r += chr(i) + ":" + str(i) + " " * (size_col - len(para)) | ||
| if count % 10 == 0: | ||
| print(r) | ||
| r = "" | ||
|
|
||
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.
Отличное начало