-
Notifications
You must be signed in to change notification settings - Fork 0
Gavrilova #11
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?
Gavrilova #11
Changes from all commits
fc049d7
0d77445
ccc700c
2e86d2e
0a15f1f
8d4dd37
ed2d42b
393e130
8cb9df2
18248c5
5a765d4
fe05599
f7fefdd
bb4d96b
c496e54
a9a2015
ea32525
a02d8e9
29bbeb6
cf108a4
69d497b
b249606
d815b04
dbd92f2
35afaeb
3b39b99
abba903
10cc86d
ffaf7f0
205b3ca
0c4d6e5
71e8ae8
1484c82
63422fb
091d391
ef71946
8da7a1b
e18ac04
d163b10
82ff4a9
824e466
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,10 @@ | ||
| def length(lst): | ||
| if not lst: | ||
| return 0 | ||
| return 1 + length(lst[1:]) | ||
|
|
||
|
|
||
| a = [1, 2, 3] | ||
| l = length(a) | ||
| print("Длина списка равна: " + str(l)) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| def myreversed(a): | ||
| return list[::-1] | ||
|
|
||
| list = [123, 'abc', 'apple'] | ||
| x = myreversed(list) | ||
| print (x) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| def to_title(a): | ||
| # return a.title() | ||
| t = a.split(' ') | ||
| for i in range(1, len(t)): | ||
| t[i] = t[i][0].upper() + t[i][1:] | ||
| return ' '.join(t) | ||
|
|
||
| s = 'orlov Ilya evgenyevich' | ||
| print (s) | ||
| s1 = to_title(s).capitalize() | ||
| print (s1) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| def count_symbol(a, s): | ||
| count = 0 | ||
| for i in a: | ||
| if i == s: | ||
| count += 1 | ||
| return count | ||
|
|
||
| test_str = 'Hi, Elvis, I am here!' | ||
| simv = 'i' | ||
| n = count_symbol(test_str, simv) | ||
| print(f'Символ {simv} встречается в строке {test_str} {str(n)} раза') | ||
| #print ('Символ ' + simv + ' встречается в строке: ' + test_str + ' '+str(n)+' раз') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| f1 = 'sourse.txt' | ||
| f2 = 'destination.txt' | ||
| try: | ||
| with open(f1, 'r') as file1: | ||
| # file1 = open(f1, 'r') | ||
| textfile1 = file1.read() | ||
| except Exception: | ||
| print(f'Файл {f1} не найден') | ||
| # print("Файл " + f1 + " не найден") | ||
| else: | ||
| try: | ||
| with open(f2, 'r') as file2: | ||
| print(f'Файл {f2} уже существует') | ||
| # file2 = open(f2, 'w') | ||
| # file2.write(textfile1) | ||
| except Exception: | ||
| with open(f2, 'w') as file2: | ||
| file2.write(textfile1) | ||
| print(textfile1) | ||
| # file1.close() | ||
| # file2.close() | ||
| with open(f2, 'r') as file2: | ||
| # file2 = open(f2, 'r') | ||
| textfile2 = file2.read() | ||
| print(textfile2) | ||
| # file2.close() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| class User: | ||
|
|
||
| name = ' ' | ||
| age = 0 | ||
| # def __init__(self, name, age): | ||
| # self.name = name | ||
| # self.age = age | ||
|
|
||
| def setName(self, name): | ||
| self.name = name | ||
|
|
||
| def getName(self): | ||
| return self.name | ||
|
|
||
| def setAge(self, age): | ||
| self.age = age | ||
|
|
||
| def getAge(self): | ||
| return self.age | ||
|
|
||
|
|
||
| class Worker(User): | ||
|
|
||
| salary = 0 | ||
| # def __init__(self, name, age, salary): | ||
| # super(Worker, self).__init__(name, age) | ||
| # self.salary = salary | ||
|
|
||
| def setSalary(self, salary): | ||
| self.salary = salary | ||
|
|
||
| def getSalary(self): | ||
| return self.salary | ||
|
|
||
|
|
||
| w1 = Worker() | ||
| w1.setName('John') | ||
| print(w1.getName()) | ||
| w1.setAge(25) | ||
| print(w1.getAge()) | ||
| w1.setSalary(1000) | ||
| print(w1.getSalary()) | ||
| w2 = Worker() | ||
| w2.setName('Jack') | ||
| print(w2.getName()) | ||
| w2.setAge(26) | ||
| print(w2.getAge()) | ||
| w2.setSalary(2000) | ||
| print(w2.getSalary()) | ||
| s = w1.getSalary() + w2.getSalary() | ||
| print(f'Сумма зарплат объектов John и Jack {s} ') | ||
| #w1 = Worker("John", 25, 1000) | ||
| #print(w1.salary) | ||
| #w2 = Worker("Jack", 26, 2000) | ||
| #print(w2.salary) | ||
| #print (w1.salary+w2.salary) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| def test1(a, b): # вывод на экран большего значения из двух чисел | ||
| if a > b: | ||
| print(a) | ||
| elif a < b: | ||
| print(b) | ||
| else: | ||
|
IlyaOrlov marked this conversation as resolved.
|
||
| print("Числа равны") | ||
|
|
||
| def test2(a, b): # возврат бол7ьшего значения из двух чисел | ||
| if a > b: | ||
| return a | ||
| elif a < b: | ||
| return b | ||
| else: | ||
|
IlyaOrlov marked this conversation as resolved.
|
||
| return None | ||
|
|
||
| a = int(input("Введите первое число ")) | ||
| b = int(input("Введите второе число ")) | ||
|
|
||
| test1(a,b) | ||
| #test2(a,b) | ||
|
|
||
| x = test2(a,b) #проверка возврвщаемого значения | ||
| print(x) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| dict = {'1': 'красный', '2': 'синий', '3': 'зеленый', '4': 'сиреневый', '5': 'голубой'} | ||
|
|
||
| line = "Камни имеют цвета: рубин 1, сапфир 2, изумруд 3, аметист 4, топаз 5, танзанит 4" | ||
|
|
||
| for i in dict.keys(): | ||
| line = line.replace(i, dict[i]) | ||
|
|
||
| print(line) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import random | ||
|
|
||
| def del_column(lst, x): | ||
| for i in range(len(lst)): | ||
| for j in reversed(range(len(lst[i]))): | ||
| if lst[i][j] == x: | ||
| for k in range(len(lst)): | ||
| del lst[k][j] | ||
|
|
||
| lst = [ | ||
| [1, 1, 2], | ||
| [1, 2, 1], | ||
| [1, 1, 1] | ||
| ] | ||
|
|
||
| print(*lst, sep='\n') | ||
| x = int(input('Введите число: ')) | ||
| del_column(lst, x) | ||
| print(*lst, sep='\n') | ||
|
|
||
| row = int(input('Введите кол-во строк: ')) | ||
| column = int(input('Введите кол-во столбцов: ')) | ||
| lst1 = [[random.randrange(1, 10) for _ in range(column)] for _ in range(row)] | ||
| print(*lst1, sep='\n') | ||
| x = int(input('Введите число: ')) | ||
| del_column(lst1, x) | ||
| print(*lst1, sep='\n') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import time | ||
| import random | ||
|
|
||
| class Man: | ||
|
|
||
| def __init__(self, name): | ||
| self.name = name | ||
|
|
||
| def solve_task(self): | ||
| print("I'm not ready yet") | ||
|
|
||
| class Pupil(Man): | ||
|
|
||
| def __init__(self, name): | ||
|
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. __init__ уже можно не указывать. Наследование позволяет Pupil переиспользовать методы Man. |
||
| self.name = name | ||
|
|
||
| def solve_task(self): | ||
| time.sleep(random.randint(3, 6)) | ||
| super().solve_task() | ||
|
|
||
| m = Man('Marya') | ||
| print(f'Are you ready {m.name}?') | ||
| m.solve_task() | ||
|
|
||
| p = Pupil('Evgeniy') | ||
| print(f'And you {p.name}?') | ||
| p.solve_task() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import tempfile | ||
| import os | ||
|
|
||
| class WrapStrToFile: | ||
|
|
||
| def __init__(self): | ||
| self.filepath = tempfile.mktemp(suffix='.txt', dir='.') | ||
|
|
||
| @property | ||
| def content(self): | ||
| try: | ||
| with open(self.filepath, 'r') as f: | ||
| data = f.read() | ||
| except Exception: | ||
| data = "Файл еще не существует" | ||
| return data | ||
|
|
||
| @content.setter | ||
| def content(self, value): | ||
| with open(self.filepath, 'w') as f: | ||
| f.write(str(value)) | ||
|
|
||
| @content.deleter | ||
| def content(self): | ||
| print('Файл удален') | ||
| # os.close(fd) | ||
| os.unlink(self.filepath) | ||
|
|
||
|
|
||
| wstf = WrapStrToFile() | ||
| print(wstf.filepath) | ||
| print(wstf.content) | ||
| wstf.content = 'Привет' | ||
| print(wstf.content) | ||
| wstf.content = 'Привет еще раз' | ||
| print(wstf.content) | ||
| del wstf.content |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #работа с классами | ||
| class Tank: | ||
|
|
||
| caption = "" | ||
| length = 0 | ||
| speed = 0 | ||
| armament = "" | ||
|
|
||
| def say_caption(self): | ||
| print (f"Наименование танка {self.caption}") | ||
|
|
||
| def say_length(self): | ||
| print (f"Длина танка {self.length}") | ||
|
|
||
| def say_speed(self): | ||
| print (f"Подвижность танка {self.speed}") | ||
|
|
||
| def say_armament(self): | ||
| print (f"Вооружение танка {self.armament}") | ||
|
|
||
| t34 = Tank() | ||
| t34.caption = "Т34" | ||
| t34.length = 5964 | ||
| t34.speed = 54 | ||
| t34.armament = "76-мм танковая пушка ф-34" | ||
|
|
||
| tiger = Tank() | ||
| tiger.caption = "Tiger" | ||
| tiger.length = 8450 | ||
| tiger.speed = 45 | ||
| tiger.armament = "88-мм KwK 36" | ||
|
|
||
| t34.say_caption() | ||
| t34.say_length() | ||
| t34.say_speed() | ||
| t34.say_armament() | ||
|
|
||
|
|
||
| tiger.say_caption() | ||
| tiger.say_length() | ||
| tiger.say_speed() | ||
| tiger.say_armament() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| def fun(a): | ||
| y = y.join(a) | ||
| print(a) | ||
|
|
||
|
|
||
| def get_arg(arg): | ||
| x = [] | ||
| while not arg.lower() == "stop": | ||
| arg = input('Введите число ') | ||
| if arg.isnumeric(): | ||
| x.append(arg) | ||
|
|
||
| elif arg != "stop": | ||
| print("Некорректный ввод") | ||
| # else: | ||
| # if arg == "stop": | ||
| # pass | ||
| # else: | ||
| # print("Некорректный ввод") | ||
| return x | ||
|
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. Лучше сделать x локальной переменной. Чем меньше в функции зависимостей от глобальных переменных - тем она более универсальная и гибкая. Например, ее проще импортировать из других модулей.
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. С x теперь все ОК. Остался arg. |
||
|
|
||
|
|
||
| # print(arg) | ||
|
|
||
| arg = 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. Этот arg и arg в функции get_arg - абсолютно разные переменные. arg в стр.25 вообще не нужен, а arg в функции get_arg надо сделать локальной переменной, убрав из списка параметров функции. Т.к. то, что в эту функцию передается (в стр. 28), никак, по сути, не используется. |
||
| y = '' | ||
| #x = [] | ||
| x = get_arg('x') | ||
| y = y.join(x) | ||
| print(y) | ||
| #fun(x) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| def check_palindrome(a): | ||
| a = a.lower() | ||
| b = a[::-1] | ||
| if a == b: | ||
| print(a, "Палиндром") | ||
| else: | ||
| print(a, "Не палиндром") | ||
|
|
||
| x = input("Введите слово: ") | ||
| check_palindrome(x) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import random | ||
|
|
||
| x=0 | ||
| number = random.randint(1, 10) | ||
|
|
||
| while True: | ||
| x = input("Введите число в диапазоне от 1 до 10:") | ||
|
|
||
| if not x.isnumeric(): | ||
| print("Вы ввели не число") | ||
| break | ||
|
|
||
| x = int(x) | ||
|
|
||
| if x > number: | ||
| print("Загаданное число меньше") | ||
| elif x < number: | ||
| print("Загаданное число больше") | ||
| else: | ||
| # x == number: | ||
| print("Вы угадали") | ||
| break |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| lst = [] | ||
|
|
||
| for x in range(1, 101): | ||
| if x % 15 == 0: | ||
| lst.append('FizzBuzz') | ||
| elif x % 3 == 0: | ||
| lst.append('Fizz') | ||
| elif x % 5 == 0: | ||
| lst.append('Buzz') | ||
| else: | ||
| lst.append(x) | ||
|
|
||
| print(lst) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| x = input("Введите число ") | ||
| for i in range(len(x)): | ||
| print(f'{i+1} цифра равна {x[i]}') |
Uh oh!
There was an error while loading. Please reload this page.