-
Notifications
You must be signed in to change notification settings - Fork 0
Volobuev first branch #69
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: main
Are you sure you want to change the base?
Changes from all commits
9635e3a
25365c8
deb6c60
76cd12a
fb9e846
774e1a8
5633d56
8a5cc92
5098e94
d9208e3
5acb0c3
b19f092
40e3da6
785ac89
87ad423
36a7b47
d689839
4397ed4
e71624f
176754d
be0f1ab
f5027e2
9ed57a3
d7fe30f
10686e4
557a41d
016fd54
d5240eb
4e7c718
136c38f
06b95af
a59e7e3
00a2aa8
0c0b3a8
5222480
f527aef
baf62ab
ce6d5cf
42a4b1e
f4526b4
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,15 @@ | ||
| def sravnenie(a): | ||
| if a % 15 == 0: | ||
| print("FizzBuzz") | ||
| else: | ||
| if a % 5 == 0: | ||
| print("Fizz") | ||
| else: | ||
| if a % 3 == 0: | ||
| print("Buzz") | ||
| else: | ||
| print(a) | ||
|
|
||
|
|
||
| for i in range(1, 101): | ||
| sravnenie(i) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| n = input("Введите пятизначное число: ") | ||
| for k in range(0, len(n)): | ||
| print(f"{k+1} цифра равна: {n[k]}") | ||
|
IlyaOrlov marked this conversation as resolved.
IlyaOrlov marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| def bukv(b, alfa): | ||
| nom = input(f"Введите порядковый номер для буквы: {b:} : ") | ||
| if nom.isdigit(): | ||
| nom = int(nom) | ||
| mon = alfavit[nom - 1] | ||
| bo1 = str(mon[1]) | ||
| if b == bo1: | ||
| print(f"Цифра соответствует букве : {bo1:}") | ||
| return nom | ||
| else: | ||
| print(f"Цифра соответствует букве {bo1:} 'попробйте еще раз") | ||
| bukv(b, alfa) | ||
| else: | ||
| print("Вместо цифры введена буква :") | ||
| bukv(b, alfa) | ||
|
|
||
|
|
||
| def buk_v(b, s, s1, alfavit): | ||
| s1 = bukv(b, alfavit) | ||
| s = s + str(s1) + " " | ||
|
|
||
| alfavit = [(1, "a"), (2,"b"),(3, "c"),(4, "d"),(5, "e"),(6, "f"),(7, "g"),(8, "h"),(9, "i"),(10, "j"),(11, "k"), | ||
| (12,"l"),(13,"m"),(14, "n"),(15, "o"),(16, "p"),(17, "q"),(18, "r"),(19, "s"),(20, "t"), | ||
| (21,"u"),(22, "v"),(23, "w"),(24, "x"),(25, "y"),(26, "z")] | ||
| print("Сегодня мы стараемся запомнить порядковый номер букв в алфавите, и набрать слово (stop)") | ||
| bs = alfavit[18] | ||
| bt = alfavit[19] | ||
| bo = alfavit[14] | ||
| bp = alfavit[15] | ||
| s = "" | ||
| for k in range(0, 4): | ||
| if k == 0: | ||
|
Owner
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. Код в стр.29-31, 34-36, 39-41, 43-45 одинаковый. Зачем его столько раз повторять?
Collaborator
Author
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. Исправил.
Owner
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. Нет. stop_alf = (alfavit[18], alfavit[19], alfavit[14], alfavit[15])
s = ""
for k in range(0, 4):
b = stop_alf[k][1]
s1 = bukv(b, alfavit)
s += str(s1) + " "или даже до stop_alf = (alfavit[18], alfavit[19], alfavit[14], alfavit[15])
s = ""
for n, b in stop_alf:
s += str(bukv(b, alfavit)) + " "В-третьих, буквы "a"..."z" и так упорядочены по таблице ASCII. Получить порядковый номер каждой буквы можно и без доп. структуры alfavit простым вычитанием порядкового номера "a". nz = ord("z") - ord("a") + 1 # получится 26Узнать символ по порядковому номеру тоже просто. Например, номер 5: b5 = chr(ord("a") + 5 - 1) # получится "e"Операции ord и chr мы проходили на 5-м занятии (примерно 58-я минута записи). Если всё же удобней работать с алфавитом как списком, имеет смысл сгенерировать его через алгоритм: alfavit = []
for i in range(1, ord("z") + 1):
b = chr(ord("a") + i - 1)
alfavit.append((i, b))Это более быстрый и гибкий подход. Если заказчик решит нумеровать буквы с 0, а не с 1, захочет проверять прописные буквы, а не строчные, поправить алгоритм гораздо проще, чем переписывать заново всю последовательность букв и цифр. if k == ...:
b = ...
buk_v(...) |
||
| b = str(bs[1]) | ||
| buk_v(b, s, s1, alfavit) | ||
| else: | ||
| if k == 1: | ||
| b = str(bt[1]) | ||
| buk_v(b, s, s1, alfavit) | ||
| else: | ||
| if k == 2: | ||
| b = str(bo[1]) | ||
| buk_v(b, s, s1, alfavit) | ||
| else: | ||
| b = str(bp[1]) | ||
| s1 = bukv(b, alfavit) | ||
| s = s + str(s1) +" " | ||
| print(f"Поздравляем, Вы ввели слово -stop-, цифры - {s}") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import random | ||
|
|
||
|
|
||
| def bukv(buk, stops): | ||
| j = 100 | ||
| for k in range(0, j): | ||
| zapros = input("Введите любое слово: ") | ||
| if zapros != stops: | ||
| print(random.choice(buk)) | ||
| else: | ||
| return | ||
|
|
||
|
|
||
| buk = ("Ты сам понял, что написал?", "Аргументируй", "И") | ||
| stops = ("хватит") | ||
|
Owner
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. Скобки здесь не нужны. |
||
| bukv(buk, stops) | ||
| print("Спасибо за беседу!") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import random | ||
|
|
||
|
|
||
| def chisl(buk, a, b): | ||
| a = int(a) | ||
| b = int(b) | ||
| buk = int(buk) | ||
| zapros = input("Угадайте загадоное число в заданном дипазоне: ") | ||
| if zapros.isdigit(): | ||
| print(f"{zapros}") | ||
| if int(zapros) == buk: | ||
| print("Угадали. ") | ||
| return zapros | ||
| else: | ||
| zapros = int(zapros) | ||
| if zapros > b: | ||
| print("Введено число больше верхнего диапазона") | ||
| else: | ||
| if zapros < a: | ||
| print("Введено число меньше нижнего диапазона") | ||
| else: | ||
| if zapros > buk: | ||
| print("Введеное число больше загадоного") | ||
| else: | ||
| print("Введеное число меньше загадоного") | ||
| chisl(buk, a, b) | ||
| else: | ||
| print("Введена точка") | ||
| return zapros | ||
|
|
||
|
|
||
| a = int(input("Введите цифру, начало диапазона : ")) | ||
| b = int(input("Введите цифру, конец диапазона : ")) | ||
| i = random.randint(a, b) | ||
| chisl(i, a, b) | ||
| print("Спасибо за игру!") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| def input_vvod(z1, z2): | ||
| if z1 > z2: | ||
| return z1 | ||
| else: | ||
| return z2 | ||
|
|
||
| def print_vivod(maxi): | ||
| print(f"Наибольшее число: {maxi}") | ||
|
|
||
|
|
||
| def print_viv(z1, z2): | ||
| if z1 > z2: | ||
| print(f"Наибольшее число: {z1}") | ||
| else: | ||
| print(f"Наибольшее число: {z2}") | ||
|
|
||
|
|
||
| print("Программа для определения наибольшего числа из двух введеных") | ||
| z1 = input("Введите первое число: ") | ||
| z2 = input("Введите второе число: ") | ||
| dx = input_vvod(z1, z2) | ||
| print_vivod(dx) | ||
| print_viv(z1, z2) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| def telo_dekor(fun): | ||
| def podch(*args, **kwargs): | ||
| print("================") | ||
| rex= fun(*args, **kwargs) | ||
| print("================") | ||
| return rex | ||
| return podch | ||
|
|
||
|
|
||
| @telo_dekor | ||
| def fun_print(a,b,c): | ||
| print(f"{a} + {b} = {c}") | ||
|
|
||
|
|
||
| def fun_sum(zn, zk): | ||
| zl = zn + zk | ||
| return zl | ||
|
|
||
|
|
||
| z1 = int(input("Введите первое число: ")) | ||
| z2 = int(input("Введите второе число: ")) | ||
| z = fun_sum(z1, z2) | ||
| fun_print(z1,z2,z) | ||
| #telo_dekor(z1, z2, z) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import random | ||
|
|
||
|
|
||
| def bukv(buky): | ||
| for k in range(0, 100): | ||
| zapros = input("Выберите одно из трех слов и введите его (Камень, Ножницы, Бумага), для выхода введите Хватит: ") | ||
| zapros = zapros.strip() | ||
| zapros = zapros.lower() | ||
|
|
||
| if zapros == buky[3]: return | ||
|
|
||
| if zapros not in buky: | ||
| print("Слово введено с ошибкой, введите слово заново") | ||
| else: | ||
| i = random.randint(0, 2) | ||
| if zapros == buky[i]: | ||
| print(f"Мы выбрали тоже: {zapros}") | ||
| else: | ||
| if i == 0: | ||
| if zapros == buky[1]: | ||
| print (f"{buky[i]} Вы проиграли") | ||
| else: | ||
| print(f"{buky[i]} Вы выиграли") | ||
| else: | ||
| if i == 1: | ||
| if zapros == buky[0]: | ||
| print (f"{buky[i]} Вы выиграли") | ||
| else: | ||
| print(f"{buk[i]} Вы проиграли") | ||
| else: | ||
| if i == 2: | ||
| if zapros == buky[0]: | ||
| print(f"{buky[i]} Вы проиграли") | ||
| else: | ||
| print(f"{buky[i]} Вы выиграли") | ||
|
|
||
|
|
||
|
|
||
| buk = ["камень", "ножницы", "бумага", "хватит"] | ||
| bukv(buk) | ||
| print("Спасибо за игру!") |
|
IlyaOrlov marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| arg = [0, 3, 24, 2, 3, 7] | ||
| print(arg) | ||
| for i in range(0, len(arg)-1): | ||
| n = i | ||
| for k in range(i + 1, len(arg)): | ||
| if arg[k] < arg[n]: | ||
| n = k | ||
| arg[i], arg[n] = arg[n], arg[i] | ||
|
Owner
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. А здесь ещё можно повесить проверку
Collaborator
Author
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. Не совсем понял предложение.
Owner
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. Да, эти присваивания необходимы. Но если внутри цикла arg = [0, 3, 24, 2, 3, 7]
print(arg)
for i in range(0, len(arg)-1):
n = i
for k in range(i+1, len(arg)):
if arg[k] < arg[n]:
n = k
if n != i:
arg[i], arg[n] = arg[n], arg[i]
print(arg)
Collaborator
Author
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. Внес изменения, получил это:
Owner
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.
Collaborator
Author
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. Спасибо, все получилось. Но мой код короче на одну строку.
Owner
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. Хороший вопрос. Давайте разбираться. Возьмём список из миллиона элементов и рассмотрим крайние случаи.
Если элементы в списке генерируются случайным образом по равномерному распределению, то вероятность обоих крайних случаев одинаковая. |
||
| print(arg) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| def fun_povtor(st): | ||
| j1 = len(st) | ||
| j2 = len(st) | ||
| for i in range(0, len(st) - 1): | ||
| for k in range(i + 1, len(st)): | ||
| if int(st[k]) == int(st[i]): | ||
|
Owner
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. Зачем здесь int?
Collaborator
Author
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. Исправил.
Owner
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. Не вижу исправления. int на месте.
Collaborator
Author
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. Сразу исправил.
Owner
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. |
||
| if k-i < j2: | ||
| j1 = st[k] | ||
| j2 = k-i | ||
| print(f"Первый повторившийся символ: {j1}") | ||
|
|
||
|
|
||
|
|
||
|
|
||
| arg = [2, 3, 4, 5, 3, 2] | ||
| print(arg) | ||
| fun_povtor(arg) | ||
|
IlyaOrlov marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| def zam(t, dik1): | ||
| n = len(t) | ||
|
Owner
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. Код в стр.3-8 можно заменить одной строкой:
Collaborator
Author
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. Вставил, код дает ошибку. Вчера и завтра не использовал, т.к. тогда нужно еще менять был и будет.
Owner
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. ОК. Исправляюсь) Вот такой строкой:
Owner
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. Но вообще идея была в том, чтоб получить независимое от конкретных значений решение: def zam(t, dik1):
for k, v in dik1.items():
t = t.replace(k, v)
return tА всеми заменами управляем только через содержимое словаря. По сути, так работает автозамена в Word, в PyCharm.
Collaborator
Author
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. Надо будет потренироваться с показанным решением. |
||
| k = t.count('дождь') | ||
| for i in range(0, k): | ||
| d = t.find('дождь') | ||
| t2 = t[0:d] + dik1['дождь'] + t[d+5:n] | ||
| t = t2 | ||
| return t | ||
|
|
||
|
|
||
| t = 'Вчера был дождь, и завтра будет дождь.' | ||
| dik = {'Вчера': 'Завтра', 'дождь': 'ветер'} | ||
| print(t) | ||
| t = zam(t, dik) | ||
| print(t) | ||
|
IlyaOrlov marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| art = [[1, 2, 3, 4], [5, 6, 2, 8], [9, 2, 11, 12], [13, 14, 15, 16]] | ||
| st = [-1, -1, -1, -1] | ||
| for i in range(0, 4): | ||
|
Owner
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. В этом цикле индекс нам особо не нужен, поэтому на операции индексирования можно сэкономить, обращаясь непосредственно к элементу: for x in art:
print(x)
Collaborator
Author
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. Что-то не разобрался как это делать.
Owner
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. Буквально подставить этот код вместо стр.3-4. |
||
| print(art[i]) | ||
|
|
||
| k = int(input("Введите цифру от 1 до 16, столбец которой нужно удалить: ")) | ||
| i1 = 0 | ||
| for i in range(0, len(art)): | ||
| for j in range(0, len(art[0])): | ||
| g = art[i] | ||
| if g[j] == k and j not in st: | ||
| st[i1] = j | ||
| i1 += 1 | ||
|
|
||
| for j1 in range(0, i1): | ||
|
IlyaOrlov marked this conversation as resolved.
|
||
| s1 = st[j1] | ||
| for i in range(0, len(art)): | ||
| g = art[i] | ||
| del(g[s1-j1]) | ||
|
|
||
| for x in art: | ||
| print(x) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| with open("Piton.txt","w",encoding= "utf-8") as f: | ||
| f.write("\tЭнтони Шоу — заядлый питонист, участник Python Software Foundation.,\n") | ||
| f.write("\tСтрасть Энтони — разбираться в сложных системах,\n") | ||
| f.write("упрощать их и обучать других людей.") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Замена Tab на пробелы | ||
| h = int(input("Введите количество пробелов вместо Tab: ")) | ||
| slist = [] | ||
| with open("Piton.txt", "r", encoding="utf-8") as f1: | ||
| for s in f1: | ||
| slist.append(s.expandtabs(tabsize=h)) | ||
| print(slist) | ||
|
|
||
| with open("Piton.txt","w",encoding= "utf-8") as f: | ||
| for i1 in range(0, len(slist)): | ||
| f.write(slist[i1]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Замена проберов на Tab | ||
| s2 = "\n" | ||
| slist = "" | ||
| with open("Piton.txt", "r", encoding="utf-8") as f1: | ||
| for s in f1: | ||
| slist += s.replace(" ", "\t") + s2 | ||
| print(slist) | ||
|
|
||
| with open("Piton.txt","w",encoding= "utf-8") as f: | ||
| f.write(slist) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # WrapStrFlle | ||
| import tempfile | ||
| import os | ||
|
|
||
|
|
||
| class WrapStrToFile: | ||
| def __init__(self): | ||
| self.filepach = tempfile.mktemp() | ||
|
|
||
| @property | ||
| def content(self): | ||
| try: | ||
| with open(self.filepach, "r", encoding="utf-8") as f1: | ||
| return f1.read() | ||
| except FileNotFoundError as e: | ||
| print(e) | ||
| return "File doesn't exist" | ||
|
|
||
| @content.setter | ||
| def content(self, value): | ||
| with open(self.filepach, "w", encoding="utf-8") as f1: | ||
| f1.write(value) | ||
|
|
||
| @content.deleter | ||
| def content(self): | ||
| os.remove(self.filepach) | ||
| print("Файл удален") | ||
|
|
||
|
|
||
| wstf = WrapStrToFile() | ||
| print(wstf.content) | ||
| wstf.content= "test str" | ||
| print(wstf.content) | ||
| wstf.content = "text 2" | ||
| print(wstf.content) | ||
| del wstf.content # после этого файла не существует |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Задание 1. Класс и экземпляры классов | ||
| class Tank_Vybor: | ||
| def __init__(self, marka, cvet, ckorost): | ||
| self.marka = marka | ||
| self.cvet = cvet | ||
| self.ckorost = ckorost | ||
|
|
||
|
|
||
| w = Tank_Vybor("T-34", "Зеленый", "50 км/ч") | ||
| print(w.marka) | ||
| print(w.cvet) | ||
| print(w.ckorost) | ||
| print("************************************") | ||
| w1 = Tank_Vybor("T-80", "Песочный", "80 км/ч") | ||
| print(w1.marka) | ||
| print(w1.cvet) | ||
| print(w1.ckorost) |

Uh oh!
There was an error while loading. Please reload this page.