last lab
This commit is contained in:
13
labPython/lab1/TheOne1.py
Executable file
13
labPython/lab1/TheOne1.py
Executable file
@@ -0,0 +1,13 @@
|
||||
r1 = 2
|
||||
r2 = 1
|
||||
pi = 3,14
|
||||
|
||||
|
||||
while True:
|
||||
x = float(input())
|
||||
y = float(input())
|
||||
|
||||
if x**2+y**2<=r1**2 and x**2+y**2>=r2**2 and (x >= 0 or y >= 0):
|
||||
print("yes")
|
||||
else:
|
||||
print("no")
|
||||
31
labPython/lab1/TheOne23.py
Executable file
31
labPython/lab1/TheOne23.py
Executable file
@@ -0,0 +1,31 @@
|
||||
x = int(input())
|
||||
x = (x - 1996) % 12
|
||||
|
||||
text = ""
|
||||
match x:
|
||||
case 0:
|
||||
text = "крыса"
|
||||
case 1:
|
||||
text = "бык"
|
||||
case 2:
|
||||
text = "тигр"
|
||||
case 3:
|
||||
text = "кролик"
|
||||
case 4:
|
||||
text = "дракон"
|
||||
case 5:
|
||||
text = "змея"
|
||||
case 6:
|
||||
text = "лошадь"
|
||||
case 7:
|
||||
text = "овца"
|
||||
case 8:
|
||||
text = "обезьяна"
|
||||
case 9:
|
||||
text = "курица"
|
||||
case 10:
|
||||
text = "собака"
|
||||
case 11:
|
||||
text = "свинья"
|
||||
|
||||
print(text)
|
||||
BIN
labPython/lab1/__pycache__/windows.cpython-313.pyc
Executable file
BIN
labPython/lab1/__pycache__/windows.cpython-313.pyc
Executable file
Binary file not shown.
53
labPython/lab1/case5.py
Executable file
53
labPython/lab1/case5.py
Executable file
@@ -0,0 +1,53 @@
|
||||
import curses
|
||||
from curses import wrapper
|
||||
|
||||
from windows import StaticWindow
|
||||
from windows import InputWindow
|
||||
|
||||
def main(stdscr):
|
||||
stdscr.clear()
|
||||
stdscr.refresh
|
||||
y, x = stdscr.getmaxyx()
|
||||
ch = 0
|
||||
text = ""
|
||||
while (ch!=24):
|
||||
|
||||
stdscr.clear()
|
||||
stdscr.refresh
|
||||
|
||||
calculate = StaticWindow((x//2)-len(text)//2-3, (y//2)+4, text,"",True)
|
||||
calculate.draw()
|
||||
|
||||
|
||||
curses.curs_set(1)
|
||||
function = InputWindow((x//2)-5, (y//2)-5, 10, 3, "function", 6)
|
||||
xInput = InputWindow((x//2)-5, (y//2)-2, 10, 3, "x", x)
|
||||
yInput = InputWindow((x//2)-5, (y//2)+1, 10, 3, "y", x)
|
||||
|
||||
function.draw()
|
||||
xInput.draw()
|
||||
yInput.draw()
|
||||
|
||||
try:
|
||||
function = int(function.editResize())
|
||||
xInput = int(xInput.editResize())
|
||||
yInput = int(yInput.editResize())
|
||||
|
||||
text = "нет такой операции"
|
||||
curses.curs_set(0)
|
||||
if function == 1:
|
||||
text = f"x+y={xInput+yInput}"
|
||||
elif function == 2:
|
||||
text = f"x-y={xInput-yInput}"
|
||||
elif function == 3:
|
||||
text = f"x*y={xInput*yInput}"
|
||||
elif function == 4:
|
||||
text = f"x/y={xInput//yInput}"
|
||||
calculate.clear()
|
||||
except:
|
||||
pass
|
||||
|
||||
calculate = StaticWindow((x//2)-len(text)//2-3, (y//2)+4, text,"",True)
|
||||
calculate.draw()
|
||||
ch = stdscr.getch()
|
||||
wrapper(main)
|
||||
12
labPython/lab1/number5_2.py
Executable file
12
labPython/lab1/number5_2.py
Executable file
@@ -0,0 +1,12 @@
|
||||
from math import sqrt
|
||||
|
||||
print("Введите координаты x1,y1")
|
||||
x1 = int(input())
|
||||
y1 = int(input())
|
||||
print("Веедите координаты x2,y2")
|
||||
x2 = int(input())
|
||||
y2 = int(input())
|
||||
|
||||
|
||||
|
||||
print(sqrt((x2-x1)**2+(y2-y1)**2))
|
||||
6
labPython/lab1/number6_7.py
Executable file
6
labPython/lab1/number6_7.py
Executable file
@@ -0,0 +1,6 @@
|
||||
print("введите R1, R2")
|
||||
R1 = float(input())
|
||||
R2 = float(input())
|
||||
|
||||
pi = 3.1415
|
||||
print((R2**2*pi) - (R1**2*pi))
|
||||
21
labPython/lab1/one45.py
Executable file
21
labPython/lab1/one45.py
Executable file
@@ -0,0 +1,21 @@
|
||||
ticket = int(input())
|
||||
# if range(str(ticket)) == 4:
|
||||
num1 = ((ticket - (ticket % 100000)) // 100000)
|
||||
num2 = ((ticket%100000 - (ticket % 10000)) // 10000)
|
||||
num3 = ((ticket%10000 - (ticket % 1000)) // 1000)
|
||||
num4 = ((ticket%1000 - (ticket % 100))// 100)
|
||||
num5 = ((ticket%100 - (ticket % 10))// 10)
|
||||
num6 = (ticket%10)
|
||||
|
||||
if num2 == 0 and num1 == 0:
|
||||
if num3+num4==num5+num6:
|
||||
print("good tocket")
|
||||
else:
|
||||
print("not good")
|
||||
else:
|
||||
if num1+num2+num3==num4+num5+num6:
|
||||
print("good ticket")
|
||||
else:
|
||||
print("not good")
|
||||
|
||||
print(num1,num2,num3,num4,num5,num6)
|
||||
277
labPython/lab1/windows.py
Executable file
277
labPython/lab1/windows.py
Executable file
@@ -0,0 +1,277 @@
|
||||
import curses
|
||||
|
||||
class InputWindow(): # Позиция x, позиция y, ширина, высота, текст окна.
|
||||
|
||||
def __init__(self, position_x, position_y, width, heigth, text="", xMax=6):
|
||||
|
||||
self.x = position_x
|
||||
|
||||
self.y = position_y
|
||||
|
||||
self.w = width
|
||||
|
||||
self.h = heigth
|
||||
|
||||
self.t = text
|
||||
|
||||
self.inputwin = curses.newwin(self.h-2, self.w-3, self.y+1, self.x+2) # Разметка окна ввода
|
||||
|
||||
self.win = curses.newwin(self.h, self.w, self.y, self.x) # Основное окно с рамкой
|
||||
|
||||
self.xMax = xMax
|
||||
|
||||
|
||||
|
||||
def draw(self):
|
||||
|
||||
|
||||
|
||||
# Главное окно
|
||||
|
||||
self.win.border() # Рамка
|
||||
|
||||
self.win.addstr(0, 1, self.t) # Надпись на окне(не более 8 символов)
|
||||
|
||||
|
||||
|
||||
self.win.refresh()
|
||||
|
||||
self.inputwin.refresh()
|
||||
|
||||
|
||||
|
||||
def edit(self): # Статическое окно
|
||||
|
||||
input = self.inputwin # Окно ввода
|
||||
|
||||
input.clear()
|
||||
|
||||
text = "" # Возвращаемый текст
|
||||
|
||||
cursX = 0 # Позиция курсора
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
|
||||
|
||||
# Каждую итерацию цикла отрисовываем окно, ждем ввод, в зависимости от ввода делаем действие
|
||||
|
||||
input.addstr(0, 0, text)
|
||||
|
||||
input.move(0, cursX)
|
||||
|
||||
self.win.refresh()
|
||||
|
||||
self.inputwin.refresh()
|
||||
|
||||
|
||||
|
||||
ch = input.getch()
|
||||
|
||||
|
||||
|
||||
if ch == 7: # Проверяем на Ctrl+g
|
||||
|
||||
return text
|
||||
|
||||
elif ch == 10: # Проверям на enter
|
||||
|
||||
return text
|
||||
|
||||
elif cursX > self.w-5:
|
||||
|
||||
StaticWindow(1, 0, f"Maximum lenght {self.w-4}")
|
||||
|
||||
|
||||
|
||||
elif ch == 127: # Проверяем на backspace
|
||||
|
||||
if text!="":
|
||||
|
||||
text = text[:-1]
|
||||
|
||||
cursX -= 1
|
||||
|
||||
input.clear()
|
||||
|
||||
input.refresh()
|
||||
|
||||
|
||||
|
||||
else: # Отрисосвываем текст
|
||||
|
||||
text += chr(ch)
|
||||
|
||||
cursX += 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def editResize(self): # Динамически масштабируемое окно
|
||||
|
||||
input = self.inputwin # Окно ввода
|
||||
|
||||
input.clear()
|
||||
|
||||
text = "" # Возвращаемый текст
|
||||
|
||||
cursX = 0 # Позиция курсора
|
||||
|
||||
while True:
|
||||
|
||||
# Каждую итерацию цикла отрисовываем окно, ждем ввод, в зависимости от ввода делаем действие
|
||||
|
||||
input.addstr(0, 0, text)
|
||||
|
||||
input.move(0, cursX)
|
||||
|
||||
self.win.refresh()
|
||||
|
||||
self.inputwin.refresh()
|
||||
|
||||
|
||||
|
||||
ch = input.getch()
|
||||
|
||||
|
||||
|
||||
if ch == 7: # Проверяем на Ctrl+g
|
||||
|
||||
return text
|
||||
|
||||
elif ch == 10: # Проверям на enter
|
||||
|
||||
return text
|
||||
|
||||
elif ch == 127: # Проверяем на backspace
|
||||
|
||||
if text!="":
|
||||
|
||||
text = text[:-1]
|
||||
|
||||
cursX -= 1
|
||||
|
||||
input.clear()
|
||||
|
||||
input.refresh()
|
||||
|
||||
|
||||
|
||||
elif len(text) <= (self.xMax - 6): # Отрисосвываем текст
|
||||
|
||||
text += chr(ch)
|
||||
|
||||
cursX += 1
|
||||
|
||||
|
||||
|
||||
if cursX > self.w-4: # Динамическое увеличение рамки и текстового поля
|
||||
|
||||
self.x -=1
|
||||
|
||||
self.w +=2
|
||||
|
||||
|
||||
|
||||
input.mvwin(self.y+1, self.x+2)
|
||||
|
||||
self.win.mvwin(self.y, self.x)
|
||||
|
||||
|
||||
|
||||
input.resize(self.h-2, self.w-3) # Разметка окна ввода
|
||||
|
||||
self.win.resize(self.h, self.w) # Основное окно с рамкой
|
||||
|
||||
|
||||
|
||||
self.win.border()
|
||||
|
||||
self.win.addstr(0, 1, self.t) # Надпись на окне(не более 8 символов)
|
||||
|
||||
|
||||
|
||||
def clear(self):
|
||||
|
||||
|
||||
|
||||
self.inputwin.clear()
|
||||
|
||||
self.inputwin.refresh()
|
||||
|
||||
|
||||
|
||||
class StaticWindow(): # Поция x, позиция y, текст
|
||||
|
||||
def __init__(self, position_x, position_y, text, textInline="", reverse=False, minHeigtg=False):
|
||||
|
||||
self.x = position_x
|
||||
|
||||
self.y = position_y
|
||||
|
||||
if len(text) < 20 and minHeigtg:
|
||||
|
||||
self.w = 24
|
||||
|
||||
else:
|
||||
|
||||
self.w = len(text)+4
|
||||
|
||||
self.h = 3
|
||||
|
||||
self.t = text
|
||||
|
||||
self.ti = textInline
|
||||
|
||||
self.r = reverse
|
||||
|
||||
|
||||
|
||||
self.win = curses.newwin(self.h, self.w, self.y, self.x)
|
||||
|
||||
|
||||
|
||||
def draw(self):
|
||||
|
||||
if self.r:
|
||||
|
||||
self.win.attron(curses.A_REVERSE)
|
||||
|
||||
self.win.border()
|
||||
|
||||
self.win.attroff(curses.A_REVERSE)
|
||||
|
||||
self.win.attron(curses.A_REVERSE)
|
||||
|
||||
self.win.addstr(0, 1, self.ti)
|
||||
|
||||
self.win.attroff(curses.A_REVERSE)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
|
||||
self.win.border()
|
||||
|
||||
self.win.addstr(0, 1, self.ti)
|
||||
|
||||
|
||||
|
||||
self.win.addstr(1,2, self.t)
|
||||
|
||||
self.win.refresh()
|
||||
|
||||
|
||||
|
||||
def clear(self):
|
||||
|
||||
|
||||
|
||||
self.win.clear()
|
||||
|
||||
self.win.refresh()
|
||||
Reference in New Issue
Block a user