last lab
This commit is contained in:
BIN
labLinux/Final_practical_assignment/final_practical.odt
Executable file
BIN
labLinux/Final_practical_assignment/final_practical.odt
Executable file
Binary file not shown.
6
labLinux/lab2/create.sh
Executable file
6
labLinux/lab2/create.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
touch my_file #создание файла
|
||||||
|
date>my_file #запись даты
|
||||||
|
pwd>>my_file #путь к файлу
|
||||||
|
who >>my_file #имя пользователя
|
||||||
|
uname -sr>>my_file #версия OC
|
||||||
11
labLinux/lab2/create2.sh
Executable file
11
labLinux/lab2/create2.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
touch my_file
|
||||||
|
id >> my_file
|
||||||
|
groups >> my_file
|
||||||
|
w >> my_file
|
||||||
|
last >> my_file
|
||||||
|
ls ~/ >>my_file
|
||||||
|
chage -l $USER >> my_file
|
||||||
|
whoami >> my_file
|
||||||
|
cat /etc/passwd >> my_file
|
||||||
|
getent passwd $USER >> my_file
|
||||||
3
labLinux/lab2/delete.sh
Executable file
3
labLinux/lab2/delete.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm ./my_file && echo 'файл успешно удалён'
|
||||||
|
echo $?
|
||||||
3
labLinux/lab2/delete2.sh
Executable file
3
labLinux/lab2/delete2.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm ./my_file && echo 'файл успешно удалён'
|
||||||
|
echo $?
|
||||||
271
labLinux/lab2/my_file
Executable file
271
labLinux/lab2/my_file
Executable file
@@ -0,0 +1,271 @@
|
|||||||
|
uid=1000(ivanbaran) gid=1000(ivanbaran) группы=1000(ivanbaran),998(wheel)
|
||||||
|
ivanbaran wheel
|
||||||
|
08:35:42 up 15 min, 1 user, load average: 0,45, 0,64, 0,44
|
||||||
|
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
|
||||||
|
ivanbara tty1 08:20 15:15 0.07s ? waitpid -e 747
|
||||||
|
ivanbar* tty1 Mon Oct 6 08:20 still logged in
|
||||||
|
reboot system boot 6.16.10-arch1-1 Mon Oct 6 08:20 still running
|
||||||
|
ivanbar* tty1 Sun Oct 5 01:16 - down (00:15)
|
||||||
|
reboot system boot 6.16.10-arch1-1 Sun Oct 5 01:15 - 01:31 (00:15)
|
||||||
|
ivanbar* tty1 Sat Oct 4 19:09 - down (00:39)
|
||||||
|
reboot system boot 6.16.10-arch1-1 Sat Oct 4 19:09 - 19:48 (00:39)
|
||||||
|
ivanbar* tty1 Sat Oct 4 16:01 - down (00:03)
|
||||||
|
reboot system boot 6.16.10-arch1-1 Sat Oct 4 16:01 - 16:05 (00:03)
|
||||||
|
ivanbar* tty1 Sat Oct 4 13:42 - down (00:47)
|
||||||
|
reboot system boot 6.16.10-arch1-1 Sat Oct 4 13:42 - 14:30 (00:47)
|
||||||
|
ivanbar* tty1 Sat Oct 4 13:37 - down (00:05)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Oct 4 13:36 - 13:42 (00:05)
|
||||||
|
ivanbar* tty1 Sat Oct 4 11:51 - down (00:50)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Oct 4 11:50 - 12:41 (00:50)
|
||||||
|
ivanbar* tty1 Sat Oct 4 10:04 - down (01:45)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Oct 4 10:04 - 11:50 (01:46)
|
||||||
|
ivanbar* tty1 Sat Oct 4 00:37 - down (02:04)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Oct 4 00:37 - 02:41 (02:04)
|
||||||
|
ivanbar* tty1 Fri Oct 3 20:14 - down (01:25)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Oct 3 20:14 - 21:40 (01:25)
|
||||||
|
ivanbar* tty1 Fri Oct 3 19:16 - down (00:44)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Oct 3 19:16 - 20:01 (00:44)
|
||||||
|
ivanbar* tty1 Fri Oct 3 15:51 - down (03:24)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Oct 3 15:51 - 19:16 (03:25)
|
||||||
|
ivanbar* tty1 Fri Oct 3 12:25 - down (00:40)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Oct 3 12:25 - 13:05 (00:40)
|
||||||
|
ivanbar* tty1 Fri Oct 3 11:42 - down (00:41)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Oct 3 11:42 - 12:24 (00:42)
|
||||||
|
ivanbar* tty1 Fri Oct 3 00:05 - down (02:46)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Oct 3 00:04 - 02:51 (02:47)
|
||||||
|
ivanbar* tty1 Thu Oct 2 17:07 - down (02:12)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Oct 2 17:07 - 19:19 (02:12)
|
||||||
|
ivanbar* pts/0 wayland-1 Thu Oct 2 16:51 - 16:58 (00:07)
|
||||||
|
ivanbar* tty1 Thu Oct 2 16:51 - down (00:15)
|
||||||
|
ivanbar* pts/0 wayland-1 Thu Oct 2 16:48 - 16:51 (00:02)
|
||||||
|
ivanbar* tty1 Thu Oct 2 16:46 - 16:51 (00:04)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Oct 2 16:46 - 17:06 (00:20)
|
||||||
|
ivanbar* pts/1 wayland-1 Thu Oct 2 16:46 - down (00:00)
|
||||||
|
ivanbar* tty1 Thu Oct 2 15:54 - down (00:51)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Oct 2 15:54 - 16:46 (00:51)
|
||||||
|
ivanbar* pts/2 wayland-1 Thu Oct 2 14:28 - 15:34 (01:05)
|
||||||
|
ivanbar* pts/1 wayland-1 Thu Oct 2 13:55 - 13:55 (00:00)
|
||||||
|
ivanbar* tty1 Thu Oct 2 13:27 - down (02:06)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Oct 2 13:27 - 15:34 (02:06)
|
||||||
|
ivanbar* tty1 Wed Oct 1 23:28 - down (02:15)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Oct 1 23:25 - 01:44 (02:18)
|
||||||
|
ivanbar* tty1 Wed Oct 1 22:21 - down (00:02)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Oct 1 22:21 - 22:24 (00:03)
|
||||||
|
ivanbar* tty1 Wed Oct 1 19:32 - down (00:24)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Oct 1 19:32 - 19:56 (00:24)
|
||||||
|
ivanbar* pts/0 wayland-1 Wed Oct 1 17:02 - 18:49 (01:47)
|
||||||
|
ivanbar* pts/0 wayland-1 Wed Oct 1 16:52 - 16:59 (00:06)
|
||||||
|
ivanbar* tty1 Wed Oct 1 15:47 - down (03:02)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Oct 1 15:47 - 18:49 (03:02)
|
||||||
|
ivanbar* pts/0 wayland-1 Wed Oct 1 15:21 - down (00:24)
|
||||||
|
ivanbar* pts/0 wayland-1 Wed Oct 1 15:12 - 15:21 (00:08)
|
||||||
|
ivanbar* tty1 Wed Oct 1 15:01 - down (00:45)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Oct 1 15:01 - 15:46 (00:45)
|
||||||
|
ivanbar* pts/0 wayland-1 Wed Oct 1 12:27 - 12:27 (00:00)
|
||||||
|
ivanbar* tty1 Wed Oct 1 11:53 - down (00:33)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Oct 1 11:53 - 12:27 (00:33)
|
||||||
|
ivanbar* tty1 Tue Sep 30 21:02 - down (01:40)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Tue Sep 30 21:02 - 22:43 (01:40)
|
||||||
|
ivanbar* pts/1 wayland-1 Tue Sep 30 15:25 - 15:25 (00:00)
|
||||||
|
ivanbar* pts/0 wayland-1 Tue Sep 30 15:22 - 15:52 (00:30)
|
||||||
|
ivanbar* pts/0 wayland-1 Tue Sep 30 14:37 - 15:15 (00:37)
|
||||||
|
ivanbar* pts/0 wayland-1 Tue Sep 30 14:23 - 14:23 (00:00)
|
||||||
|
ivanbar* tty1 Tue Sep 30 14:19 - down (01:33)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Tue Sep 30 14:16 - 15:52 (01:36)
|
||||||
|
ivanbar* tty1 Tue Sep 30 13:52 - down (00:02)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Tue Sep 30 13:52 - 13:55 (00:02)
|
||||||
|
ivanbar* pts/1 wayland-1 Tue Sep 30 12:49 - 12:49 (00:00)
|
||||||
|
ivanbar* pts/0 wayland-1 Tue Sep 30 12:11 - 13:08 (00:57)
|
||||||
|
ivanbar* pts/1 wayland-1 Tue Sep 30 11:05 - 11:19 (00:13)
|
||||||
|
ivanbar* pts/1 wayland-1 Tue Sep 30 11:05 - 11:05 (00:00)
|
||||||
|
ivanbar* pts/1 wayland-1 Tue Sep 30 11:05 - 11:05 (00:00)
|
||||||
|
ivanbar* pts/0 wayland-1 Tue Sep 30 10:59 - 12:06 (01:07)
|
||||||
|
ivanbar* pts/0 wayland-1 Tue Sep 30 10:58 - 10:58 (00:00)
|
||||||
|
ivanbar* tty1 Tue Sep 30 10:47 - down (02:21)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Tue Sep 30 10:46 - 13:08 (02:22)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 19:34 - 19:34 (00:00)
|
||||||
|
ivanbar* pts/7 wayland-1 Mon Sep 29 19:08 - 19:25 (00:16)
|
||||||
|
ivanbar* pts/7 wayland-1 Mon Sep 29 18:56 - 18:58 (00:02)
|
||||||
|
ivanbar* pts/6 wayland-1 Mon Sep 29 18:42 - 19:21 (00:38)
|
||||||
|
ivanbar* tty1 Mon Sep 29 17:14 - down (02:19)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Mon Sep 29 17:11 - 19:34 (02:22)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 17:01 - 17:01 (00:00)
|
||||||
|
ivanbar* tty1 Mon Sep 29 16:55 - down (00:06)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Mon Sep 29 16:54 - 17:01 (00:06)
|
||||||
|
ivanbar* pts/6 wayland-1 Mon Sep 29 15:42 - 15:42 (00:00)
|
||||||
|
ivanbar* tty1 Mon Sep 29 12:20 - down (03:21)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Mon Sep 29 12:20 - 15:42 (03:22)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 11:39 - 12:19 (00:40)
|
||||||
|
ivanbar* tty1 Mon Sep 29 11:15 - down (01:04)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Mon Sep 29 11:15 - 12:19 (01:04)
|
||||||
|
ivanbar* pts/2 wayland-1 Mon Sep 29 09:08 - 09:29 (00:21)
|
||||||
|
ivanbar* pts/1 wayland-1 Mon Sep 29 08:53 - 09:09 (00:15)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 08:43 - 09:09 (00:25)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 08:43 - 08:43 (00:00)
|
||||||
|
ivanbar* pts/1 wayland-1 Mon Sep 29 08:43 - 08:43 (00:00)
|
||||||
|
ivanbar* pts/1 wayland-1 Mon Sep 29 08:40 - 08:42 (00:02)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 08:16 - 08:43 (00:26)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 08:16 - 08:16 (00:00)
|
||||||
|
ivanbar* pts/1 wayland-1 Mon Sep 29 08:16 - 08:16 (00:00)
|
||||||
|
ivanbar* pts/0 wayland-1 Mon Sep 29 08:15 - 08:16 (00:00)
|
||||||
|
ivanbar* tty1 Mon Sep 29 08:12 - down (01:16)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Mon Sep 29 08:12 - 09:29 (01:17)
|
||||||
|
ivanbar* pts/4 wayland-1 Sun Sep 28 12:03 - 12:03 (00:00)
|
||||||
|
ivanbar* tty1 Sun Sep 28 10:47 - down (01:15)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sun Sep 28 10:47 - 12:03 (01:15)
|
||||||
|
ivanbar* pts/2 wayland-1 Sun Sep 28 10:20 - 10:47 (00:26)
|
||||||
|
ivanbar* tty1 Sun Sep 28 09:27 - down (01:19)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sun Sep 28 09:27 - 10:47 (01:19)
|
||||||
|
ivanbar* pts/3 wayland-1 Sat Sep 27 23:24 - 23:24 (00:00)
|
||||||
|
ivanbar* pts/2 wayland-1 Sat Sep 27 23:22 - 00:04 (00:41)
|
||||||
|
ivanbar* pts/2 wayland-1 Sat Sep 27 23:22 - 23:22 (00:00)
|
||||||
|
ivanbar* tty1 Sat Sep 27 22:51 - down (01:12)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 22:51 - 00:04 (01:12)
|
||||||
|
ivanbar* pts/2 wayland-1 Sat Sep 27 22:22 - 22:33 (00:10)
|
||||||
|
ivanbar* tty1 Sat Sep 27 22:08 - down (00:24)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 22:08 - 22:33 (00:24)
|
||||||
|
ivanbar* pts/1 wayland-1 Sat Sep 27 20:29 - 20:58 (00:29)
|
||||||
|
ivanbar* tty1 Sat Sep 27 20:28 - down (00:30)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 20:28 - 20:58 (00:30)
|
||||||
|
ivanbar* pts/3 tmux(7000).%0 Sat Sep 27 13:59 - 14:00 (00:01)
|
||||||
|
ivanbar* tty1 Sat Sep 27 13:34 - down (00:28)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 13:34 - 14:03 (00:28)
|
||||||
|
ivanbar* tty1 Sat Sep 27 13:14 - down (00:19)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 13:14 - 13:34 (00:19)
|
||||||
|
ivanbar* tty1 Sat Sep 27 12:26 - down (00:48)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 12:26 - 13:14 (00:48)
|
||||||
|
ivanbar* tty1 Sat Sep 27 12:18 - down (00:04)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 12:18 - 12:22 (00:04)
|
||||||
|
ivanbar* tty1 Sat Sep 27 12:07 - down (00:10)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 12:07 - 12:17 (00:10)
|
||||||
|
ivanbar* tty1 Sat Sep 27 11:35 - down (00:21)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 11:35 - 11:57 (00:21)
|
||||||
|
ivanbar* tty4 Sat Sep 27 11:34 - 11:34 (00:00)
|
||||||
|
ivanbar* tty1 Sat Sep 27 11:26 - down (00:08)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 11:26 - 11:35 (00:08)
|
||||||
|
ivanbar* tty3 Sat Sep 27 11:26 - 11:26 (00:00)
|
||||||
|
ivanbar* tty1 Sat Sep 27 11:25 - down (00:00)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 11:25 - 11:26 (00:00)
|
||||||
|
ivanbar* tty1 Sat Sep 27 11:24 - down (00:00)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 11:24 - 11:25 (00:00)
|
||||||
|
ivanbar* tty1 Sat Sep 27 11:22 - down (00:01)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 11:22 - 11:24 (00:02)
|
||||||
|
ivanbar* tty1 Sat Sep 27 11:13 - down (00:08)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 11:12 - 11:21 (00:08)
|
||||||
|
ivanbar* tty1 Sat Sep 27 11:03 - down (00:00)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 11:02 - 11:03 (00:01)
|
||||||
|
ivanbar* tty1 Sat Sep 27 09:04 - down (01:57)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Sat Sep 27 09:04 - 11:02 (01:57)
|
||||||
|
ivanbar* tty1 Fri Sep 26 13:55 - down (00:04)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 13:55 - 14:00 (00:04)
|
||||||
|
ivanbar* tty1 Fri Sep 26 13:47 - down (00:07)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 13:47 - 13:55 (00:07)
|
||||||
|
ivanbar* tty1 Fri Sep 26 13:00 - down (00:00)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 12:59 - 13:00 (00:00)
|
||||||
|
ivanbar* tty1 Fri Sep 26 12:32 - down (00:27)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 12:32 - 12:59 (00:27)
|
||||||
|
ivanbar* tty1 Fri Sep 26 11:24 - down (01:07)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 11:23 - 12:31 (01:07)
|
||||||
|
ivanbar* tty1 Fri Sep 26 10:08 - down (00:01)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 10:08 - 10:09 (00:01)
|
||||||
|
ivanbar* tty1 Fri Sep 26 10:07 - down (00:00)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 10:06 - 10:07 (00:00)
|
||||||
|
ivanbar* tty1 Fri Sep 26 10:00 - down (00:06)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 09:59 - 10:06 (00:06)
|
||||||
|
ivanbar* tty1 Fri Sep 26 09:32 - down (00:26)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 09:32 - 09:59 (00:27)
|
||||||
|
ivanbar* tty1 Fri Sep 26 09:17 - down (00:14)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Fri Sep 26 09:17 - 09:32 (00:15)
|
||||||
|
ivanbar* tty1 Thu Sep 25 21:03 - down (00:47)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 21:03 - 21:51 (00:47)
|
||||||
|
ivanbar* tty1 Thu Sep 25 20:59 - down (00:03)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 20:59 - 21:03 (00:04)
|
||||||
|
ivanbar* tty1 Thu Sep 25 20:39 - down (00:19)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 20:39 - 20:58 (00:19)
|
||||||
|
ivanbar* tty1 Thu Sep 25 20:00 - down (00:37)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 20:00 - 20:38 (00:38)
|
||||||
|
ivanbar* tty1 Thu Sep 25 15:15 - down (00:37)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 15:15 - 15:53 (00:38)
|
||||||
|
ivanbar* tty1 Thu Sep 25 14:39 - down (00:07)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 14:39 - 14:46 (00:07)
|
||||||
|
ivanbar* tty1 Thu Sep 25 14:37 - down (00:02)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 14:37 - 14:39 (00:02)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 13:03 - 13:03 (00:00)
|
||||||
|
ivanbar* tty1 Thu Sep 25 12:23 - down (00:40)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 12:23 - 13:03 (00:40)
|
||||||
|
ivanbar* tty1 Thu Sep 25 12:16 - down (00:06)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 12:16 - 12:22 (00:06)
|
||||||
|
ivanbar* tty1 Thu Sep 25 11:19 - down (00:56)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 11:19 - 12:16 (00:56)
|
||||||
|
ivanbar* tty1 Thu Sep 25 09:54 - down (01:18)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 09:54 - 11:12 (01:18)
|
||||||
|
ivanbar* tty1 Thu Sep 25 01:48 - down (00:53)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 01:48 - 02:42 (00:53)
|
||||||
|
ivanbar* tty1 Thu Sep 25 01:25 - down (00:23)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 01:24 - 01:48 (00:23)
|
||||||
|
ivanbar* tty1 Thu Sep 25 00:51 - down (00:33)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 00:51 - 01:24 (00:33)
|
||||||
|
ivanbar* tty1 Thu Sep 25 00:49 - down (00:01)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 00:49 - 00:50 (00:01)
|
||||||
|
ivanbar* tty1 Thu Sep 25 00:44 - down (00:04)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Thu Sep 25 00:44 - 00:49 (00:04)
|
||||||
|
ivanbar* tty1 Wed Sep 24 22:54 - down (01:48)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 22:54 - 00:43 (01:49)
|
||||||
|
ivanbar* tty1 Wed Sep 24 21:40 - down (00:10)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 21:40 - 21:50 (00:10)
|
||||||
|
ivanbar* tty1 Wed Sep 24 20:28 - down (00:18)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 20:28 - 20:47 (00:18)
|
||||||
|
ivanbar* tty1 Wed Sep 24 20:26 - down (00:01)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 20:26 - 20:28 (00:01)
|
||||||
|
ivanbar* tty4 Wed Sep 24 20:18 - 20:26 (00:07)
|
||||||
|
ivanbar* tty1 Wed Sep 24 20:17 - down (00:08)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 20:17 - 20:26 (00:09)
|
||||||
|
ivanbar* tty4 Wed Sep 24 20:14 - 20:17 (00:02)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 20:14 - 20:17 (00:02)
|
||||||
|
ivanbar* tty4 Wed Sep 24 20:08 - 20:14 (00:05)
|
||||||
|
ivanbar* tty1 Wed Sep 24 20:07 - down (00:06)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 20:07 - 20:14 (00:06)
|
||||||
|
ivanbar* tty1 Wed Sep 24 19:56 - down (00:11)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 19:56 - 20:07 (00:11)
|
||||||
|
ivanbar* tty1 Wed Sep 24 19:32 - down (00:23)
|
||||||
|
reboot system boot 6.16.8-arch3-1 Wed Sep 24 19:32 - 19:56 (00:23)
|
||||||
|
reboot system boot 6.15.4-arch2-1 Wed Sep 24 18:28 - 18:28 (00:00)
|
||||||
|
|
||||||
|
wtmp begins Wed Sep 24 18:28:45 2025
|
||||||
|
Downloads
|
||||||
|
Pictures
|
||||||
|
Programs
|
||||||
|
Projects
|
||||||
|
Videos
|
||||||
|
Последний раз пароль был изменён : сен 24, 2025
|
||||||
|
Срок действия пароля истекает : никогда
|
||||||
|
Пароль будет деактивирован через : никогда
|
||||||
|
Срок действия учётной записи истекает : никогда
|
||||||
|
Минимальное количество дней между сменой пароля : 0
|
||||||
|
Максимальное количество дней между сменой пароля : 99999
|
||||||
|
Количество дней с предупреждением перед деактивацией пароля : 7
|
||||||
|
ivanbaran
|
||||||
|
root:x:0:0::/root:/usr/bin/bash
|
||||||
|
bin:x:1:1::/:/usr/bin/nologin
|
||||||
|
daemon:x:2:2::/:/usr/bin/nologin
|
||||||
|
mail:x:8:12::/var/spool/mail:/usr/bin/nologin
|
||||||
|
ftp:x:14:11::/srv/ftp:/usr/bin/nologin
|
||||||
|
http:x:33:33::/srv/http:/usr/bin/nologin
|
||||||
|
nobody:x:65534:65534:Kernel Overflow User:/:/usr/bin/nologin
|
||||||
|
dbus:x:81:81:System Message Bus:/:/usr/bin/nologin
|
||||||
|
systemd-coredump:x:979:979:systemd Core Dumper:/:/usr/bin/nologin
|
||||||
|
systemd-network:x:978:978:systemd Network Management:/:/usr/bin/nologin
|
||||||
|
systemd-oom:x:977:977:systemd Userspace OOM Killer:/:/usr/bin/nologin
|
||||||
|
systemd-journal-remote:x:976:976:systemd Journal Remote:/:/usr/bin/nologin
|
||||||
|
systemd-resolve:x:975:975:systemd Resolver:/:/usr/bin/nologin
|
||||||
|
systemd-timesync:x:974:974:systemd Time Synchronization:/:/usr/bin/nologin
|
||||||
|
tss:x:973:973:tss user for tpm2:/:/usr/bin/nologin
|
||||||
|
uuidd:x:972:972:UUID generator helper daemon:/var/lib/libuuid:/usr/bin/nologin
|
||||||
|
alpm:x:971:971:Arch Linux Package Management:/:/usr/bin/nologin
|
||||||
|
polkitd:x:102:102:User for polkitd:/:/usr/bin/nologin
|
||||||
|
avahi:x:970:970:Avahi mDNS/DNS-SD daemon:/:/usr/bin/nologin
|
||||||
|
ivanbaran:x:1000:1000::/home/ivanbaran:/usr/bin/fish
|
||||||
|
git:x:969:969:git daemon user:/:/usr/bin/git-shell
|
||||||
|
rtkit:x:133:133:RealtimeKit:/proc:/usr/bin/nologin
|
||||||
|
sddm:x:967:967:SDDM Greeter Account:/var/lib/sddm:/usr/bin/nologin
|
||||||
|
ivanbaran:x:1000:1000::/home/ivanbaran:/usr/bin/fish
|
||||||
3
labLinux/lab2/test.sh
Executable file
3
labLinux/lab2/test.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
cat ./my_file
|
||||||
|
echo $?
|
||||||
3
labLinux/lab2/test2.sh
Executable file
3
labLinux/lab2/test2.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
cat ./my_file
|
||||||
|
echo $?
|
||||||
17
labLinux/lab3/FizzBuzz.sh
Executable file
17
labLinux/lab3/FizzBuzz.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
num=$((RANDOM % 101 + 100))
|
||||||
|
echo "Случайное число: $num"
|
||||||
|
|
||||||
|
for (( i=1; i<=$num; i++ )); do
|
||||||
|
echo "текущее число $i"
|
||||||
|
if (( num % 15 == 0 )); then
|
||||||
|
echo "FizzBuzz"
|
||||||
|
elif (( num % 3 == 0 )); then
|
||||||
|
echo "Fizz"
|
||||||
|
elif (( num % 5 == 0 )); then
|
||||||
|
echo "Buzz"
|
||||||
|
else
|
||||||
|
echo "$num"
|
||||||
|
fi
|
||||||
|
echo "--------------------------"
|
||||||
|
done
|
||||||
14
labLinux/lab3/factorial.sh
Executable file
14
labLinux/lab3/factorial.sh
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
factorial() {
|
||||||
|
if [ $1 -le 1 ]; then
|
||||||
|
echo 1
|
||||||
|
else
|
||||||
|
local prev=$(factorial $(( $1 - 1 )))
|
||||||
|
echo $(( $1 * prev ))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
read -p "Введите число: " n
|
||||||
|
result=$(factorial $n)
|
||||||
|
echo "Факториал $n равен $result"
|
||||||
10
labLinux/lab3/find.sh
Executable file
10
labLinux/lab3/find.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
for item in "$HOME"/*; do
|
||||||
|
if [ -d "$item" ]; then
|
||||||
|
echo "$item — это директория"
|
||||||
|
elif [ -f "$item" ]; then
|
||||||
|
echo "$item — это файл"
|
||||||
|
else
|
||||||
|
echo "$item — это не файл и не директория"
|
||||||
|
fi
|
||||||
|
done
|
||||||
10
labLinux/lab3/nums.sh
Executable file
10
labLinux/lab3/nums.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
read -p "Введите числа через пробел: " -a nums
|
||||||
|
sum=0
|
||||||
|
|
||||||
|
for n in "${nums[@]}"; do
|
||||||
|
((sum += n))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Сумма чисел: $sum"
|
||||||
6
labLinux/lab3/oneToten.sh
Executable file
6
labLinux/lab3/oneToten.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for i in {1..10}; do
|
||||||
|
echo $i
|
||||||
|
|
||||||
|
done
|
||||||
9
labLinux/lab4/main.py
Executable file
9
labLinux/lab4/main.py
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
import sys
|
||||||
|
def main(n:int) -> int:
|
||||||
|
if n < 998:
|
||||||
|
n = n+1
|
||||||
|
return main(n)
|
||||||
|
else:
|
||||||
|
return n
|
||||||
|
print(main(0))
|
||||||
|
print(sys.getrecursionlimit()) # Обычно выведет 1000
|
||||||
13
labLinux/lab4/text1.txt
Executable file
13
labLinux/lab4/text1.txt
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
редактор Vim — это мощный инструмент для работы с текстом,
|
||||||
|
созданный с упором на скорость и эффективность.
|
||||||
|
Он управляется в основном с клавиатуры,
|
||||||
|
что позволяет опытным пользователям выполнять сложные операции без лишних движений.
|
||||||
|
Вместо привычных кнопок и меню здесь используются команды,
|
||||||
|
которые можно комбинировать,
|
||||||
|
создавая собственные последовательности действий.
|
||||||
|
редактор Vim поддерживает множество режимов работы: обычный,
|
||||||
|
вставки, визуальный и командный.
|
||||||
|
Такой подход помогает разделить процесс редактирования,
|
||||||
|
набора и управления, что снижает вероятность ошибок и ускоряет работу.
|
||||||
|
Благодаря системе плагинов и широким возможностям настройки,
|
||||||
|
редактор Vim можно адаптировать под любые задачи — от написания кода до ведения заметок
|
||||||
26
labLinux/lab4/text2.txt
Executable file
26
labLinux/lab4/text2.txt
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
Какая ночь! Я не могу.
|
||||||
|
Не спится мне. Такая лунность.
|
||||||
|
Еще как будто берегу
|
||||||
|
В душе утраченную юность.
|
||||||
|
Подруга охладевших лет,
|
||||||
|
Не называй игру любовью,
|
||||||
|
Пусть лучше этот лунный свет
|
||||||
|
Ко мне струится к изголовью.
|
||||||
|
Пусть искаженные черты
|
||||||
|
Он обрисовывает смело, —
|
||||||
|
Ведь разлюбить не сможешь ты,
|
||||||
|
Как полюбить ты не сумела.
|
||||||
|
|
||||||
|
Повтор стиха:
|
||||||
|
Какая ночь! Я не могу.
|
||||||
|
Не спится мне. Такая лунность.
|
||||||
|
Еще как будто берегу
|
||||||
|
В душе утраченную юность.
|
||||||
|
Подруга охладевших лет,
|
||||||
|
Не называй игру любовью,
|
||||||
|
Пусть лучше этот лунный свет
|
||||||
|
Ко мне струится к изголовью.
|
||||||
|
Пусть искаженные черты
|
||||||
|
Он обрисовывает смело, —
|
||||||
|
Ведь разлюбить не сможешь ты,
|
||||||
|
Как полюбить ты не сумела.
|
||||||
30
labLinux/lab5/capter1.txt
Executable file
30
labLinux/lab5/capter1.txt
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
Всё началось в 1917-02-23, когда город впервые услышал выстрелы на Невском.
|
||||||
|
На следующий день, 1917-02-24, улицы заполнились людьми с красными флагами.
|
||||||
|
Я тогда работал на Путиловском заводе и не знал, чем всё это закончится.
|
||||||
|
К 1917.03.01 уже не было ни полиции, ни начальников.
|
||||||
|
Власть будто растворилась в холодном воздухе.
|
||||||
|
Я писал брату 1917-03-05, что чувствую запах перемен.
|
||||||
|
Ответ пришёл только 1917-03-12 — он боялся, что мы повторим судьбу Франции.
|
||||||
|
Когда наступило 1917-04-03, в город вернулся Ленин.
|
||||||
|
Толпа встречала его у Финляндского вокзала, словно спасителя.
|
||||||
|
Я стоял в конце площади и не понимал, чего ждать дальше.
|
||||||
|
К 1917-05-20 начались первые забастовки против временного правительства.
|
||||||
|
На заводе говорили, что скоро всё решится.
|
||||||
|
1917-06-10 стало ясно — нас ждёт новая буря.
|
||||||
|
В тот день город гудел, как раскалённая печь.
|
||||||
|
1917-07-04 выстрелы прозвучали у самой реки.
|
||||||
|
1917-07-05 утром мы уже знали: восстание подавлено.
|
||||||
|
Кто-то исчез, кто-то ушёл на фронт.
|
||||||
|
1917-08-31 на завод пришёл новый комиссар с красной звездой на шапке.
|
||||||
|
Он говорил просто: “Теперь всё будет по-новому”.
|
||||||
|
1917-09-15 хлеба стало меньше, а очереди — длиннее.
|
||||||
|
Но в глазах людей всё чаще мелькала надежда.
|
||||||
|
1917-10-23 я видел, как солдаты грузили винтовки у Смольного.
|
||||||
|
1917-10-25 город снова гремел от залпов.
|
||||||
|
Я не спал двое суток и слышал, как колокола били тревогу.
|
||||||
|
1917-10-26 утром сказали: Зимний взят.
|
||||||
|
Мы просто смотрели друг на друга, не веря.
|
||||||
|
1917-11-01 я получил письмо от брата: “Ты жив?”
|
||||||
|
Я ответил коротко — “Да, но всё изменилось”.
|
||||||
|
1917-12-10 мы уже работали под красным флагом.
|
||||||
|
И я понимал, что началась новая эпоха.
|
||||||
10
labLinux/lab5/capter2.txt
Executable file
10
labLinux/lab5/capter2.txt
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
Всё началось в 1917-02-23, когда город впервые услыша
|
||||||
|
На следующий день, 1917-02-24, улицы заполнились людьЗадача:Сегодня я вышел на улицу и TODO почувствовал свежий ветер.
|
||||||
|
Я тогда работал на Путиловском заводе и не знал, чем Задача:Птицы пели, создавая атмосферу TODO спокойствия и умиротворения.
|
||||||
|
К 1917.03.01 уже не было ни полиции, ни начальников. Задача:Я решил пройтись по парку, TODO наслаждаясь солнечными лучами.
|
||||||
|
Задача:Вдруг я заметил TODO красивый цветок, который хотел сфотографировать.
|
||||||
|
Задача:Возвращаясь домой, я размышлял о TODO планах на будущее.
|
||||||
|
Задача:Вечером я сел с чашкой TODO чая и записал все впечатления дня в дневник.
|
||||||
|
Задача:Мои мысли были сосредоточены на TODO важной встрече завтра.
|
||||||
|
Задача:TODO: составить список дел на день и приоритеты.
|
||||||
|
Задача:Прогулка помогла мне очистить TODO разум и почувствовать легкость.
|
||||||
9
labLinux/lab5/capter3.txt
Executable file
9
labLinux/lab5/capter3.txt
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
Всё началось в 1917-02-23, когда город впервые услыша
|
||||||
|
Удалить: составить список дел на завтра и приоритеты.
|
||||||
|
На следующий день, 1917-02-24, улицы заполнились людь
|
||||||
|
Я тогда работал на Путиловском заводе и не знал, чем
|
||||||
|
К father 1917.03.01 уже не было ни полиции, ни начальников.
|
||||||
|
разделительная строка
|
||||||
|
Удалить: father составить список дел на завтра и приоритеты.
|
||||||
|
|
||||||
|
|
||||||
BIN
labLinux/lab7/lab7.odt
Executable file
BIN
labLinux/lab7/lab7.odt
Executable file
Binary file not shown.
BIN
labLinux/lab8/lab8.odt
Executable file
BIN
labLinux/lab8/lab8.odt
Executable file
Binary file not shown.
1
labPython/ind_project
Submodule
1
labPython/ind_project
Submodule
Submodule labPython/ind_project added at aac191e4d4
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()
|
||||||
BIN
labPython/lab14/task_1.bin
Executable file
BIN
labPython/lab14/task_1.bin
Executable file
Binary file not shown.
11
labPython/lab14/task_1.py
Executable file
11
labPython/lab14/task_1.py
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
# task Name: File2
|
||||||
|
# Дано имя файла и целое число N (> 1). Создать файл целых чисел
|
||||||
|
# с даннымименемизаписать в него N первых положительных четных чисел (2, 4, …).
|
||||||
|
|
||||||
|
N = int(input())
|
||||||
|
|
||||||
|
with open("task_1.bin", "wb") as binfile:
|
||||||
|
i = 0
|
||||||
|
while i != N:
|
||||||
|
i += 2
|
||||||
|
binfile.write(i.to_bytes(4, byteorder="big"))
|
||||||
14
labPython/lab15/data.txt
Normal file
14
labPython/lab15/data.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
1
|
||||||
|
11
|
||||||
|
10
|
||||||
|
16 11 2002 3
|
||||||
|
14 11 2003 4
|
||||||
|
14 11 2000 5
|
||||||
|
18 11 2000 3
|
||||||
|
14 11 2003 8
|
||||||
|
14 11 2000 7
|
||||||
|
19 11 2005 4
|
||||||
|
14 11 2003 5
|
||||||
|
12 11 2002 5
|
||||||
|
13 11 2000 5
|
||||||
|
2
|
||||||
BIN
labPython/lab15/students.bin
Normal file
BIN
labPython/lab15/students.bin
Normal file
Binary file not shown.
79
labPython/lab15/task_1.py
Normal file
79
labPython/lab15/task_1.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
class FitnessRecord:
|
||||||
|
def __init__(self, month, year, client_code, duration):
|
||||||
|
self.month = int(month)
|
||||||
|
self.year = int(year)
|
||||||
|
self.client_code = int(client_code)
|
||||||
|
self.duration = int(duration)
|
||||||
|
|
||||||
|
|
||||||
|
def run_task_c4():
|
||||||
|
while True:
|
||||||
|
print("1. Ввести данные и найти результат")
|
||||||
|
print("0. Выход")
|
||||||
|
|
||||||
|
choice = input("Выберите действие: ")
|
||||||
|
|
||||||
|
if choice == "0":
|
||||||
|
break
|
||||||
|
elif choice == "1":
|
||||||
|
try:
|
||||||
|
n_input = input("Введите количество записей N: ")
|
||||||
|
if not n_input.isdigit():
|
||||||
|
raise ValueError("N должно быть целым числом.")
|
||||||
|
n = int(n_input)
|
||||||
|
|
||||||
|
records = []
|
||||||
|
for i in range(n):
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
line = input(
|
||||||
|
f"Запись {i + 1} (<Месяц> <Год> <Код> <Часы>): "
|
||||||
|
).split()
|
||||||
|
if len(line) != 4:
|
||||||
|
raise ValueError("Нужно ввести 4 числа через пробел.")
|
||||||
|
|
||||||
|
m, y, c, d = map(int, line)
|
||||||
|
|
||||||
|
if not (1 <= m <= 12):
|
||||||
|
raise ValueError("Месяц: 1-12")
|
||||||
|
if not (2000 <= y <= 2010):
|
||||||
|
raise ValueError("Год: 2000-2010")
|
||||||
|
if not (10 <= c <= 99):
|
||||||
|
raise ValueError("Код: 10-99")
|
||||||
|
if not (1 <= d <= 30):
|
||||||
|
raise ValueError("Часы: 1-30")
|
||||||
|
|
||||||
|
records.append(FitnessRecord(m, y, c, d))
|
||||||
|
break
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"Ошибка ввода: {e}. Попробуйте еще раз.")
|
||||||
|
|
||||||
|
if not records:
|
||||||
|
print("Список пуст.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
best_rec = records[0]
|
||||||
|
for i in range(1, len(records)):
|
||||||
|
current = records[i]
|
||||||
|
if current.duration > best_rec.duration:
|
||||||
|
best_rec = current
|
||||||
|
elif current.duration == best_rec.duration:
|
||||||
|
if (current.year > best_rec.year) or (
|
||||||
|
current.year == best_rec.year
|
||||||
|
and current.month >= best_rec.month
|
||||||
|
):
|
||||||
|
best_rec = current
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"\nРезультат: {best_rec.duration} {best_rec.year} {best_rec.month}"
|
||||||
|
)
|
||||||
|
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"Критическая ошибка: {e}")
|
||||||
|
else:
|
||||||
|
print("Неверный пункт меню.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run_task_c4()
|
||||||
|
|
||||||
121
labPython/lab15/task_2.py
Normal file
121
labPython/lab15/task_2.py
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import pickle
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
class Student:
|
||||||
|
def __init__(self, surname, name, grade, extra_data):
|
||||||
|
self.surname = surname
|
||||||
|
self.name = name
|
||||||
|
self.grade = int(grade)
|
||||||
|
self.extra_data = extra_data
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
base = f"{self.surname:<15} | {self.name:<15} | {self.grade:<5} | "
|
||||||
|
if self.grade == 1:
|
||||||
|
return base + f"Скорость: {self.extra_data:<10}"
|
||||||
|
elif self.grade == 4:
|
||||||
|
return base + f"Балл аттест.: {self.extra_data:<10}"
|
||||||
|
elif self.grade in [2, 3]:
|
||||||
|
return base + f"Математика: {self.extra_data:<10}"
|
||||||
|
return base
|
||||||
|
|
||||||
|
|
||||||
|
def input_student():
|
||||||
|
surname = input("Введите фамилию: ")
|
||||||
|
name = input("Введите имя: ")
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
grade = int(input("Введите класс (1-4): "))
|
||||||
|
if grade not in [1, 2, 3, 4]:
|
||||||
|
raise ValueError
|
||||||
|
break
|
||||||
|
except ValueError:
|
||||||
|
print("Ошибка: введите класс от 1 до 4.")
|
||||||
|
|
||||||
|
extra_data = None
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
if grade == 1:
|
||||||
|
extra_data = int(input("Скорость чтения (слов/мин): "))
|
||||||
|
elif grade == 4:
|
||||||
|
extra_data = float(input("Балл аттестации (1-100): "))
|
||||||
|
if not (1 <= extra_data <= 100):
|
||||||
|
raise ValueError
|
||||||
|
elif grade in [2, 3]:
|
||||||
|
extra_data = float(input("Оценка по математике (1-10): "))
|
||||||
|
if not (1 <= extra_data <= 10):
|
||||||
|
raise ValueError
|
||||||
|
break
|
||||||
|
except ValueError:
|
||||||
|
print("Некорректные данные для этого класса.")
|
||||||
|
|
||||||
|
return Student(surname, name, grade, extra_data)
|
||||||
|
|
||||||
|
|
||||||
|
def save_to_binary(filename, students):
|
||||||
|
with open(filename, "wb") as f:
|
||||||
|
pickle.dump(students, f)
|
||||||
|
|
||||||
|
|
||||||
|
def read_from_binary(filename):
|
||||||
|
if not os.path.exists(filename):
|
||||||
|
return []
|
||||||
|
with open(filename, "rb") as f:
|
||||||
|
return pickle.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
def run_task_2():
|
||||||
|
filename = "students.bin"
|
||||||
|
while True:
|
||||||
|
print("\n--- Меню: Ученики (Бинарные файлы) ---")
|
||||||
|
print("1. Ввести N учеников вручную и сохранить")
|
||||||
|
print("2. Создать файл со случайными данными")
|
||||||
|
print("3. Прочитать файл и вывести таблицу")
|
||||||
|
print("0. Выход")
|
||||||
|
|
||||||
|
choice = input("Ваш выбор: ")
|
||||||
|
|
||||||
|
if choice == "0":
|
||||||
|
break
|
||||||
|
elif choice == "1":
|
||||||
|
try:
|
||||||
|
n = int(input("Введите N: "))
|
||||||
|
students = [input_student() for _ in range(n)]
|
||||||
|
save_to_binary(filename, students)
|
||||||
|
except ValueError:
|
||||||
|
print("Ошибка ввода числа.")
|
||||||
|
elif choice == "2":
|
||||||
|
surnames = ["Иванов", "Петров", "Сидоров", "Смирнов"]
|
||||||
|
names = ["Алексей", "Мария", "Иван", "Анна"]
|
||||||
|
random_students = []
|
||||||
|
for _ in range(5):
|
||||||
|
g = random.randint(1, 4)
|
||||||
|
if g == 1:
|
||||||
|
ex = random.randint(30, 100)
|
||||||
|
elif g == 4:
|
||||||
|
ex = round(random.uniform(50.0, 100.0), 1)
|
||||||
|
else:
|
||||||
|
ex = round(random.uniform(2.0, 10.0), 1)
|
||||||
|
random_students.append(
|
||||||
|
Student(random.choice(surnames), random.choice(names), g, ex)
|
||||||
|
)
|
||||||
|
save_to_binary(filename, random_students)
|
||||||
|
print("Файл заполнен случайными данными.")
|
||||||
|
elif choice == "3":
|
||||||
|
data = read_from_binary(filename)
|
||||||
|
if not data:
|
||||||
|
print("Файл пуст или не существует.")
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"\n{'Фамилия':<15} | {'Имя':<15} | {'Класс':<5} | Доп. информация"
|
||||||
|
)
|
||||||
|
print("-" * 60)
|
||||||
|
for s in data:
|
||||||
|
print(s)
|
||||||
|
else:
|
||||||
|
print("Неверный выбор.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run_task_2()
|
||||||
89
labPython/lab15/task_3.py
Normal file
89
labPython/lab15/task_3.py
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
class FitnessRecord:
|
||||||
|
def __init__(self, duration, client_code, year, month):
|
||||||
|
self.duration = duration
|
||||||
|
self.client_code = client_code
|
||||||
|
self.year = year
|
||||||
|
self.month = month
|
||||||
|
|
||||||
|
|
||||||
|
def solve():
|
||||||
|
while True:
|
||||||
|
print("\n--- Меню ExamTaskC16 ---")
|
||||||
|
print("1. Ввести данные и выполнить расчет")
|
||||||
|
print("2. Выход")
|
||||||
|
|
||||||
|
choice = input("Выберите вариант: ")
|
||||||
|
|
||||||
|
if choice == "2":
|
||||||
|
break
|
||||||
|
elif choice == "1":
|
||||||
|
try:
|
||||||
|
k_code = int(input("Введите код клиента K (10-99): "))
|
||||||
|
n = int(input("Введите количество строк N: "))
|
||||||
|
|
||||||
|
records = []
|
||||||
|
for i in range(n):
|
||||||
|
print(f"Строка {i + 1} из {n}")
|
||||||
|
line = input(
|
||||||
|
"Формат <Продолжительность> <Код клиента> <Год> <Номер месяца>: "
|
||||||
|
).split()
|
||||||
|
|
||||||
|
if len(line) != 4:
|
||||||
|
print("Ошибка: должно быть 4 числа.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
dur, code, yr, mnth = map(int, line)
|
||||||
|
records.append(FitnessRecord(dur, code, yr, mnth))
|
||||||
|
|
||||||
|
target_records = [r for r in records if r.client_code == k_code]
|
||||||
|
|
||||||
|
if not target_records:
|
||||||
|
print("Нет данных")
|
||||||
|
continue
|
||||||
|
|
||||||
|
years = {}
|
||||||
|
for r in target_records:
|
||||||
|
if r.duration == 0:
|
||||||
|
continue
|
||||||
|
if r.year not in years:
|
||||||
|
years[r.year] = []
|
||||||
|
years[r.year].append(r)
|
||||||
|
|
||||||
|
if not years:
|
||||||
|
print("Нет данных")
|
||||||
|
continue
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for year in years:
|
||||||
|
year_records = years[year]
|
||||||
|
|
||||||
|
min_dur = min(r.duration for r in year_records)
|
||||||
|
|
||||||
|
candidates = [r for r in year_records if r.duration == min_dur]
|
||||||
|
|
||||||
|
best_month_record = max(candidates, key=lambda x: x.month)
|
||||||
|
|
||||||
|
results.append(
|
||||||
|
{
|
||||||
|
"duration": min_dur,
|
||||||
|
"year": year,
|
||||||
|
"month": best_month_record.month,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
results.sort(key=lambda x: (x["duration"], x["year"]))
|
||||||
|
|
||||||
|
print("\nРезультат:")
|
||||||
|
for res in results:
|
||||||
|
print(f"{res['duration']} {res['year']} {res['month']}")
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
print("Ошибка: вводите только целые числа.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Произошла ошибка: {e}")
|
||||||
|
else:
|
||||||
|
print("Неверный выбор.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
solve()
|
||||||
2
labPython/lab16/data.txt
Normal file
2
labPython/lab16/data.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
10
|
||||||
|
70 65 39 94 8 16 22 58 63 15
|
||||||
44
labPython/lab16/task_1.py
Normal file
44
labPython/lab16/task_1.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data, next=None):
|
||||||
|
self.data = data
|
||||||
|
self.next = next
|
||||||
|
|
||||||
|
|
||||||
|
def push(top, d):
|
||||||
|
return Node(d, top)
|
||||||
|
|
||||||
|
|
||||||
|
def print_stack(top):
|
||||||
|
cur = top
|
||||||
|
while cur:
|
||||||
|
print(cur.data, end=" ")
|
||||||
|
cur = cur.next
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
top = None
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - создать стек")
|
||||||
|
print("2 - добавить элемент")
|
||||||
|
print("3 - показать стек")
|
||||||
|
print("0 - выход")
|
||||||
|
c = input(">> ")
|
||||||
|
|
||||||
|
if c == "1":
|
||||||
|
top = None
|
||||||
|
arr = list(map(int, input("Введите числа: ").split()))
|
||||||
|
for x in arr:
|
||||||
|
top = push(top, x)
|
||||||
|
elif c == "2":
|
||||||
|
d = int(input("Введите D: "))
|
||||||
|
top = push(top, d)
|
||||||
|
print("Новая вершина:", top.data if top else None)
|
||||||
|
elif c == "3":
|
||||||
|
print_stack(top)
|
||||||
|
elif c == "0":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
|
|
||||||
75
labPython/lab16/task_2.py
Normal file
75
labPython/lab16/task_2.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.next = None
|
||||||
|
|
||||||
|
|
||||||
|
def enqueue(head, tail, d):
|
||||||
|
node = Node(d)
|
||||||
|
if not head:
|
||||||
|
return node, node
|
||||||
|
tail.next = node
|
||||||
|
return head, node
|
||||||
|
|
||||||
|
|
||||||
|
def merge(h1, h2):
|
||||||
|
if not h1:
|
||||||
|
return h2
|
||||||
|
if not h2:
|
||||||
|
return h1
|
||||||
|
|
||||||
|
if h1.data < h2.data:
|
||||||
|
head = h1
|
||||||
|
h1 = h1.next
|
||||||
|
else:
|
||||||
|
head = h2
|
||||||
|
h2 = h2.next
|
||||||
|
|
||||||
|
cur = head
|
||||||
|
|
||||||
|
while h1 and h2:
|
||||||
|
if h1.data < h2.data:
|
||||||
|
cur.next = h1
|
||||||
|
h1 = h1.next
|
||||||
|
else:
|
||||||
|
cur.next = h2
|
||||||
|
h2 = h2.next
|
||||||
|
cur = cur.next
|
||||||
|
|
||||||
|
cur.next = h1 if h1 else h2
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
def print_q(h):
|
||||||
|
while h:
|
||||||
|
print(h.data, end=" ")
|
||||||
|
h = h.next
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
h1 = t1 = None
|
||||||
|
h2 = t2 = None
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - создать очередь 1")
|
||||||
|
print("2 - создать очередь 2")
|
||||||
|
print("3 - объединить")
|
||||||
|
print("0 - выход")
|
||||||
|
c = input(">> ")
|
||||||
|
|
||||||
|
if c == "1":
|
||||||
|
h1 = t1 = None
|
||||||
|
for x in map(int, input().split()):
|
||||||
|
h1, t1 = enqueue(h1, t1, x)
|
||||||
|
elif c == "2":
|
||||||
|
h2 = t2 = None
|
||||||
|
for x in map(int, input().split()):
|
||||||
|
h2, t2 = enqueue(h2, t2, x)
|
||||||
|
elif c == "3":
|
||||||
|
res = merge(h1, h2)
|
||||||
|
print_q(res)
|
||||||
|
elif c == "0":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("Ошибка")
|
||||||
43
labPython/lab16/task_3.py
Normal file
43
labPython/lab16/task_3.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.next = None
|
||||||
|
|
||||||
|
|
||||||
|
def build(arr):
|
||||||
|
head = None
|
||||||
|
for x in reversed(arr):
|
||||||
|
node = Node(x)
|
||||||
|
node.next = head
|
||||||
|
head = node
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
def find_second(head):
|
||||||
|
count = 0
|
||||||
|
while head:
|
||||||
|
if head.data % 6 == 0:
|
||||||
|
count += 1
|
||||||
|
if count == 2:
|
||||||
|
return head
|
||||||
|
head = head.next
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - создать список")
|
||||||
|
print("2 - найти элемент")
|
||||||
|
print("0 - выход")
|
||||||
|
c = input(">> ")
|
||||||
|
|
||||||
|
if c == "1":
|
||||||
|
arr = list(map(int, input().split()))
|
||||||
|
head = build(arr)
|
||||||
|
elif c == "2":
|
||||||
|
res = find_second(head)
|
||||||
|
print(res.data if res else "nil")
|
||||||
|
elif c == "0":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("Ошибка")
|
||||||
77
labPython/lab16/task_4.py
Normal file
77
labPython/lab16/task_4.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.next = None
|
||||||
|
|
||||||
|
|
||||||
|
def build(arr):
|
||||||
|
head = None
|
||||||
|
for x in reversed(arr):
|
||||||
|
node = Node(x)
|
||||||
|
node.next = head
|
||||||
|
head = node
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
def process(head, m):
|
||||||
|
if not head:
|
||||||
|
return head
|
||||||
|
|
||||||
|
dummy = Node(0)
|
||||||
|
dummy.next = head
|
||||||
|
prev = dummy
|
||||||
|
cur = head
|
||||||
|
i = 1
|
||||||
|
|
||||||
|
while cur:
|
||||||
|
if i % 2 == 0:
|
||||||
|
node = Node(m)
|
||||||
|
prev.next = node
|
||||||
|
node.next = cur
|
||||||
|
prev = cur
|
||||||
|
cur = cur.next
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
prev = cur
|
||||||
|
cur = cur.next
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
return dummy.next
|
||||||
|
|
||||||
|
|
||||||
|
def print_list(h):
|
||||||
|
while h:
|
||||||
|
print(h.data, end=" ")
|
||||||
|
h = h.next
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
def print_last_ref(h):
|
||||||
|
if not h:
|
||||||
|
print("None")
|
||||||
|
return
|
||||||
|
while h.next:
|
||||||
|
h = h.next
|
||||||
|
print(h)
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - создать список")
|
||||||
|
print("2 - обработать")
|
||||||
|
print("3 - вывести ссылку на последний элемент")
|
||||||
|
print("0 - выход")
|
||||||
|
c = input(">> ")
|
||||||
|
|
||||||
|
if c == "1":
|
||||||
|
head = build(list(map(int, input().split())))
|
||||||
|
elif c == "2":
|
||||||
|
m = int(input("M: "))
|
||||||
|
head = process(head, m)
|
||||||
|
print_list(head)
|
||||||
|
elif c == "3":
|
||||||
|
print_last_ref(head)
|
||||||
|
elif c == "0":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("Ошибка")
|
||||||
56
labPython/lab16/task_5.py
Normal file
56
labPython/lab16/task_5.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# task: ListWork62 / Создание убывающего списка из файла
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.next = None
|
||||||
|
|
||||||
|
|
||||||
|
def insert_desc(head, x):
|
||||||
|
node = Node(x)
|
||||||
|
if not head or x > head.data:
|
||||||
|
node.next = head
|
||||||
|
return node
|
||||||
|
cur = head
|
||||||
|
while cur.next and cur.next.data > x:
|
||||||
|
cur = cur.next
|
||||||
|
node.next = cur.next
|
||||||
|
cur.next = node
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
def print_list(h):
|
||||||
|
while h:
|
||||||
|
print(h.data, end=" ")
|
||||||
|
h = h.next
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - создать файл")
|
||||||
|
print("2 - обработать файл")
|
||||||
|
print("0 - выход")
|
||||||
|
c = input(">> ")
|
||||||
|
|
||||||
|
if c == "1":
|
||||||
|
n = int(input("N: "))
|
||||||
|
arr = [random.randint(1, 100) for _ in range(n)]
|
||||||
|
with open("data.txt", "w") as f:
|
||||||
|
f.write(str(n) + "\n")
|
||||||
|
f.write(" ".join(map(str, arr)))
|
||||||
|
elif c == "2":
|
||||||
|
with open("data.txt") as f:
|
||||||
|
n = int(f.readline())
|
||||||
|
arr = list(map(int, f.readline().split()))
|
||||||
|
head = None
|
||||||
|
for x in arr:
|
||||||
|
head = insert_desc(head, x)
|
||||||
|
print_list(head)
|
||||||
|
elif c == "0":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("Ошибка")
|
||||||
63
labPython/lab17/task_1.py
Normal file
63
labPython/lab17/task_1.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.prev = None
|
||||||
|
self.next = None
|
||||||
|
|
||||||
|
|
||||||
|
def create_list(arr):
|
||||||
|
if not arr:
|
||||||
|
return None
|
||||||
|
head = Node(arr[0])
|
||||||
|
cur = head
|
||||||
|
for x in arr[1:]:
|
||||||
|
n = Node(x)
|
||||||
|
cur.next = n
|
||||||
|
n.prev = cur
|
||||||
|
cur = n
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
def print_list(head):
|
||||||
|
res = []
|
||||||
|
while head:
|
||||||
|
res.append(str(head.data))
|
||||||
|
head = head.next
|
||||||
|
print("Список:", " ".join(res) if res else "null")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_odd_positions(head):
|
||||||
|
index = 1
|
||||||
|
cur = head
|
||||||
|
new_head = None
|
||||||
|
last = None
|
||||||
|
while cur:
|
||||||
|
nxt = cur.next
|
||||||
|
if index % 2 == 0:
|
||||||
|
if not new_head:
|
||||||
|
new_head = cur
|
||||||
|
cur.prev = None
|
||||||
|
else:
|
||||||
|
last.next = cur
|
||||||
|
cur.prev = last
|
||||||
|
last = cur
|
||||||
|
index += 1
|
||||||
|
cur = nxt
|
||||||
|
if last:
|
||||||
|
last.next = None
|
||||||
|
return new_head
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - Ввести список\n0 - Выход")
|
||||||
|
cmd = input("Выбор: ")
|
||||||
|
if cmd == "0":
|
||||||
|
break
|
||||||
|
if cmd == "1":
|
||||||
|
arr = list(map(int, input("Введите числа: ").split()))
|
||||||
|
head = create_list(arr)
|
||||||
|
head = remove_odd_positions(head)
|
||||||
|
print_list(head)
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
58
labPython/lab17/task_2.py
Normal file
58
labPython/lab17/task_2.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.prev = None
|
||||||
|
self.next = None
|
||||||
|
|
||||||
|
|
||||||
|
def create_list(arr):
|
||||||
|
if not arr:
|
||||||
|
return None, None
|
||||||
|
head = Node(arr[0])
|
||||||
|
cur = head
|
||||||
|
for x in arr[1:]:
|
||||||
|
n = Node(x)
|
||||||
|
cur.next = n
|
||||||
|
n.prev = cur
|
||||||
|
cur = n
|
||||||
|
return head, cur
|
||||||
|
|
||||||
|
|
||||||
|
def print_list(head):
|
||||||
|
res = []
|
||||||
|
cur = head
|
||||||
|
while cur:
|
||||||
|
res.append(str(cur.data))
|
||||||
|
cur = cur.next
|
||||||
|
print("Список:", " ".join(res))
|
||||||
|
|
||||||
|
|
||||||
|
def shift(head, last, k):
|
||||||
|
if not head:
|
||||||
|
return head, last
|
||||||
|
last.next = head
|
||||||
|
head.prev = last
|
||||||
|
cur = head
|
||||||
|
for _ in range(k):
|
||||||
|
cur = cur.next
|
||||||
|
new_head = cur
|
||||||
|
new_last = cur.prev
|
||||||
|
new_last.next = None
|
||||||
|
new_head.prev = None
|
||||||
|
return new_head, new_last
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - Ввести список\n0 - Выход")
|
||||||
|
cmd = input("Выбор: ")
|
||||||
|
if cmd == "0":
|
||||||
|
break
|
||||||
|
if cmd == "1":
|
||||||
|
arr = list(map(int, input("Введите числа: ").split()))
|
||||||
|
k = int(input("Введите K: "))
|
||||||
|
head, last = create_list(arr)
|
||||||
|
head, last = shift(head, last, k)
|
||||||
|
print_list(head)
|
||||||
|
except:
|
||||||
|
print("Ошибка")
|
||||||
80
labPython/lab17/task_3.py
Normal file
80
labPython/lab17/task_3.py
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.prev = None
|
||||||
|
self.next = None
|
||||||
|
|
||||||
|
|
||||||
|
class IntList:
|
||||||
|
def __init__(self, head):
|
||||||
|
self.first = head
|
||||||
|
self.last = head
|
||||||
|
self.current = head
|
||||||
|
while self.last and self.last.next:
|
||||||
|
self.last = self.last.next
|
||||||
|
|
||||||
|
def ToFirst(self):
|
||||||
|
self.current = self.first
|
||||||
|
|
||||||
|
def ToNext(self):
|
||||||
|
if self.current and self.current.next:
|
||||||
|
self.current = self.current.next
|
||||||
|
|
||||||
|
def SetData(self, d):
|
||||||
|
if self.current:
|
||||||
|
self.current.data = d
|
||||||
|
|
||||||
|
def IsLast(self):
|
||||||
|
return self.current == self.last
|
||||||
|
|
||||||
|
def process(self):
|
||||||
|
self.ToFirst()
|
||||||
|
index = 1
|
||||||
|
count = 0
|
||||||
|
while self.current:
|
||||||
|
count += 1
|
||||||
|
if index % 2 == 1:
|
||||||
|
self.SetData(0)
|
||||||
|
if self.IsLast():
|
||||||
|
break
|
||||||
|
self.ToNext()
|
||||||
|
index += 1
|
||||||
|
return count
|
||||||
|
|
||||||
|
def print_list(self):
|
||||||
|
cur = self.first
|
||||||
|
res = []
|
||||||
|
while cur:
|
||||||
|
res.append(str(cur.data))
|
||||||
|
cur = cur.next
|
||||||
|
print("Список:", " ".join(res))
|
||||||
|
|
||||||
|
|
||||||
|
def create(arr):
|
||||||
|
if not arr:
|
||||||
|
return None
|
||||||
|
head = Node(arr[0])
|
||||||
|
cur = head
|
||||||
|
for x in arr[1:]:
|
||||||
|
n = Node(x)
|
||||||
|
cur.next = n
|
||||||
|
n.prev = cur
|
||||||
|
cur = n
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - Ввести список\n0 - Выход")
|
||||||
|
cmd = input("Выбор: ")
|
||||||
|
if cmd == "0":
|
||||||
|
break
|
||||||
|
if cmd == "1":
|
||||||
|
arr = list(map(int, input("Введите числа: ").split()))
|
||||||
|
head = create(arr)
|
||||||
|
lst = IntList(head)
|
||||||
|
n = lst.process()
|
||||||
|
print("Количество:", n)
|
||||||
|
lst.print_list()
|
||||||
|
except:
|
||||||
|
print("Ошибка")
|
||||||
65
labPython/lab17/task_4.py
Normal file
65
labPython/lab17/task_4.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
class Node:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
self.prev = self
|
||||||
|
self.next = self
|
||||||
|
|
||||||
|
|
||||||
|
def create_barrier_list(arr):
|
||||||
|
barrier = Node(0)
|
||||||
|
last = barrier
|
||||||
|
for x in arr:
|
||||||
|
n = Node(x)
|
||||||
|
n.prev = last
|
||||||
|
n.next = barrier
|
||||||
|
last.next = n
|
||||||
|
barrier.prev = n
|
||||||
|
last = n
|
||||||
|
return barrier
|
||||||
|
|
||||||
|
|
||||||
|
def print_list(barrier):
|
||||||
|
cur = barrier.next
|
||||||
|
res = []
|
||||||
|
while cur != barrier:
|
||||||
|
res.append(str(cur.data))
|
||||||
|
cur = cur.next
|
||||||
|
print("Список:", " ".join(res) if res else "пусто")
|
||||||
|
|
||||||
|
|
||||||
|
def split(barrier, current):
|
||||||
|
new_barrier = Node(0)
|
||||||
|
if current == barrier:
|
||||||
|
return new_barrier
|
||||||
|
last = barrier.prev
|
||||||
|
new_barrier.next = current
|
||||||
|
new_barrier.prev = last
|
||||||
|
current.prev.next = barrier
|
||||||
|
barrier.prev = current.prev
|
||||||
|
current.prev = new_barrier
|
||||||
|
last.next = new_barrier
|
||||||
|
return new_barrier
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print("\n1 - Ввести список\n0 - Выход")
|
||||||
|
cmd = input("Выбор: ")
|
||||||
|
if cmd == "0":
|
||||||
|
break
|
||||||
|
if cmd == "1":
|
||||||
|
arr = list(map(int, input("Введите числа: ").split()))
|
||||||
|
barrier = create_barrier_list(arr)
|
||||||
|
print_list(barrier)
|
||||||
|
idx = int(input("Индекс текущего элемента (с 1): "))
|
||||||
|
cur = barrier.next
|
||||||
|
for _ in range(idx - 1):
|
||||||
|
if cur != barrier:
|
||||||
|
cur = cur.next
|
||||||
|
new_barrier = split(barrier, cur)
|
||||||
|
print("Первый список:")
|
||||||
|
print_list(barrier)
|
||||||
|
print("Второй список:")
|
||||||
|
print_list(new_barrier)
|
||||||
|
except:
|
||||||
|
print("Ошибка")
|
||||||
89
labPython/lab18-19/task_1.py
Normal file
89
labPython/lab18-19/task_1.py
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
def __init__(self):
|
||||||
|
self.red = 2021
|
||||||
|
self.green = 2022
|
||||||
|
self.current = "Игрок"
|
||||||
|
|
||||||
|
def get_divisors(self, n):
|
||||||
|
return [i for i in range(1, n + 1) if n % i == 0]
|
||||||
|
|
||||||
|
def move(self, color, n):
|
||||||
|
if color == "r":
|
||||||
|
if self.green == 0:
|
||||||
|
return False
|
||||||
|
if n in self.get_divisors(self.green) and n <= self.red:
|
||||||
|
self.red -= n
|
||||||
|
return True
|
||||||
|
elif color == "g":
|
||||||
|
if self.red == 0:
|
||||||
|
return False
|
||||||
|
if n in self.get_divisors(self.red) and n <= self.green:
|
||||||
|
self.green -= n
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def computer_move(self):
|
||||||
|
if self.red == 0 and self.green == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
options = []
|
||||||
|
|
||||||
|
if self.red > 0 and self.green > 0:
|
||||||
|
for d in self.get_divisors(self.green):
|
||||||
|
if d <= self.red:
|
||||||
|
options.append(("r", d))
|
||||||
|
for d in self.get_divisors(self.red):
|
||||||
|
if d <= self.green:
|
||||||
|
options.append(("g", d))
|
||||||
|
|
||||||
|
if not options:
|
||||||
|
return
|
||||||
|
|
||||||
|
color, n = random.choice(options)
|
||||||
|
self.move(color, n)
|
||||||
|
|
||||||
|
if color == "r":
|
||||||
|
print(f"Компьютер убрал {n} красных камней")
|
||||||
|
else:
|
||||||
|
print(f"Компьютер убрал {n} зелёных камней")
|
||||||
|
|
||||||
|
def is_over(self):
|
||||||
|
return self.red == 0 and self.green == 0
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
game = Game()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print(f"\nКрасные: {game.red}, Зелёные: {game.green}")
|
||||||
|
|
||||||
|
if game.current == "Игрок":
|
||||||
|
try:
|
||||||
|
color = input("Выберите цвет (r/g) или exit: ")
|
||||||
|
if color == "exit":
|
||||||
|
break
|
||||||
|
|
||||||
|
n = int(input("Введите количество: "))
|
||||||
|
|
||||||
|
if game.move(color, n):
|
||||||
|
if game.is_over():
|
||||||
|
print("Вы победили!")
|
||||||
|
break
|
||||||
|
game.current = "Компьютер"
|
||||||
|
else:
|
||||||
|
print("Некорректный ход")
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
|
|
||||||
|
else:
|
||||||
|
game.computer_move()
|
||||||
|
if game.is_over():
|
||||||
|
print("Победил компьютер")
|
||||||
|
break
|
||||||
|
game.current = "Игрок"
|
||||||
|
|
||||||
|
if input("Сыграть ещё? (y/n): ") != "y":
|
||||||
|
break
|
||||||
55
labPython/lab18-19/task_2.py
Normal file
55
labPython/lab18-19/task_2.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
def __init__(self):
|
||||||
|
self.sticks = [10.0]
|
||||||
|
self.current = "Игрок"
|
||||||
|
|
||||||
|
def can_move(self):
|
||||||
|
return any(s >= 1 for s in self.sticks)
|
||||||
|
|
||||||
|
def split(self, index, x):
|
||||||
|
stick = self.sticks[index]
|
||||||
|
if stick < 1 or x <= 0 or x >= stick:
|
||||||
|
return False
|
||||||
|
self.sticks.pop(index)
|
||||||
|
self.sticks.append(x)
|
||||||
|
self.sticks.append(stick - x)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def computer_move(self):
|
||||||
|
for i, s in enumerate(self.sticks):
|
||||||
|
if s >= 1:
|
||||||
|
x = round(s / 2, 2)
|
||||||
|
self.split(i, x)
|
||||||
|
print(f"Компьютер ломает палочку {s} на {x} и {round(s - x, 2)}")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
game = Game()
|
||||||
|
while True:
|
||||||
|
print("\nПалочки:", game.sticks)
|
||||||
|
if not game.can_move():
|
||||||
|
print(f"Проиграл {game.current}")
|
||||||
|
break
|
||||||
|
|
||||||
|
if game.current == "Игрок":
|
||||||
|
try:
|
||||||
|
cmd = input("Введите индекс палочки и длину разлома (или exit): ")
|
||||||
|
if cmd == "exit":
|
||||||
|
break
|
||||||
|
i, x = cmd.split()
|
||||||
|
if game.split(int(i), float(x)):
|
||||||
|
game.current = "Компьютер"
|
||||||
|
else:
|
||||||
|
print("Ошибка хода")
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
|
else:
|
||||||
|
game.computer_move()
|
||||||
|
game.current = "Игрок"
|
||||||
|
|
||||||
|
if input("Сыграть ещё? (y/n): ") != "y":
|
||||||
|
break
|
||||||
69
labPython/lab18-19/task_3.py
Normal file
69
labPython/lab18-19/task_3.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import random
|
||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
def __init__(self):
|
||||||
|
self.cells = ["_"] * 10
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
print("".join(self.cells))
|
||||||
|
|
||||||
|
def set_digit(self, pos, digit):
|
||||||
|
if 0 <= pos < 10 and self.cells[pos] == "_":
|
||||||
|
self.cells[pos] = str(digit)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def computer_move(self):
|
||||||
|
free = [i for i, x in enumerate(self.cells) if x == "_"]
|
||||||
|
if free:
|
||||||
|
pos = random.choice(free)
|
||||||
|
digit = random.randint(0, 9)
|
||||||
|
self.cells[pos] = str(digit)
|
||||||
|
print(f"Компьютер поставил {digit} в позицию {pos}")
|
||||||
|
|
||||||
|
def result(self):
|
||||||
|
num = int("".join(self.cells))
|
||||||
|
root = int(math.sqrt(num))
|
||||||
|
return root * root == num
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
game = Game()
|
||||||
|
|
||||||
|
print("\nПервый этап (ваши ходы)")
|
||||||
|
while True:
|
||||||
|
game.show()
|
||||||
|
cmd = input("Введите позицию и цифру (или stop): ")
|
||||||
|
if cmd == "stop":
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
pos, digit = map(int, cmd.split())
|
||||||
|
if not game.set_digit(pos, digit):
|
||||||
|
print("Ошибка")
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
|
|
||||||
|
print("\nХод компьютера")
|
||||||
|
game.computer_move()
|
||||||
|
|
||||||
|
print("\nФинальный этап")
|
||||||
|
while "_" in game.cells:
|
||||||
|
game.show()
|
||||||
|
try:
|
||||||
|
pos, digit = map(int, input("Введите позицию и цифру: ").split())
|
||||||
|
if not game.set_digit(pos, digit):
|
||||||
|
print("Ошибка")
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
|
|
||||||
|
game.show()
|
||||||
|
|
||||||
|
if game.result():
|
||||||
|
print("Вы выиграли!")
|
||||||
|
else:
|
||||||
|
print("Победил компьютер")
|
||||||
|
|
||||||
|
if input("Сыграть ещё? (y/n): ") != "y":
|
||||||
|
break
|
||||||
16
labPython/lab2/Series15.py
Executable file
16
labPython/lab2/Series15.py
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
K = int(input())
|
||||||
|
numlist=[]
|
||||||
|
num = 1
|
||||||
|
while(num!=0):
|
||||||
|
num = int(input())
|
||||||
|
numlist.append(num)
|
||||||
|
|
||||||
|
count=0
|
||||||
|
for i in range(len(numlist)):
|
||||||
|
if numlist[i] > K:
|
||||||
|
print(i)
|
||||||
|
count =1
|
||||||
|
break
|
||||||
|
|
||||||
|
if count == 0:
|
||||||
|
print(numlist[-1])
|
||||||
29
labPython/lab2/TheTwo16.py
Executable file
29
labPython/lab2/TheTwo16.py
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
# print("Введите число N")
|
||||||
|
# N = int(input())
|
||||||
|
#
|
||||||
|
# def fac(x: int): # факториал числа
|
||||||
|
# return _fac (x*2, x)
|
||||||
|
#
|
||||||
|
# def _fac(x: int, y: int):
|
||||||
|
# if x > y:
|
||||||
|
# return (y * _fac(x, y+1))
|
||||||
|
# else:
|
||||||
|
# return y
|
||||||
|
#
|
||||||
|
# x = 0
|
||||||
|
# if N <= 12:
|
||||||
|
# for i in range(1, N+1):
|
||||||
|
# step = i**i
|
||||||
|
# factorial = fac(i)
|
||||||
|
# x += step / factorial
|
||||||
|
# print(x)
|
||||||
|
|
||||||
|
N = int(input())
|
||||||
|
s = 0
|
||||||
|
for i in range(1, N + 1):
|
||||||
|
p = 1
|
||||||
|
for j in range(i, 2 * i + 1):
|
||||||
|
p *= j
|
||||||
|
s += i**2 / p
|
||||||
|
|
||||||
|
print(s)
|
||||||
28
labPython/lab2/TheTwo20.py
Executable file
28
labPython/lab2/TheTwo20.py
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
# print("Введите число")
|
||||||
|
# num = int(input())
|
||||||
|
# micronum = 0
|
||||||
|
# i=1
|
||||||
|
# list=[]
|
||||||
|
# while num != micronum:
|
||||||
|
# micronum = (num%(10**i)-num%(10**(i-1)))//(10**(i-1))
|
||||||
|
# list.insert(0, micronum)
|
||||||
|
# print (list)
|
||||||
|
# micronum = num%(10**i)
|
||||||
|
# i+=1
|
||||||
|
#
|
||||||
|
# max = 0
|
||||||
|
# count = 0
|
||||||
|
# maxcount = 0
|
||||||
|
# for i in list:
|
||||||
|
# count += 1
|
||||||
|
# if i > max:
|
||||||
|
# max = i
|
||||||
|
# maxcount = count
|
||||||
|
#
|
||||||
|
# print(f"Максимальное цифра{max}, индекс {maxcount}")
|
||||||
|
|
||||||
|
N = int(input())
|
||||||
|
s = str(N)[::-1]
|
||||||
|
m = min(s)
|
||||||
|
print("Минимальная цифра:", m)
|
||||||
|
print("Порядковый номер:", s.index(m) + 1)
|
||||||
17
labPython/lab2/While18.py
Executable file
17
labPython/lab2/While18.py
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
# num = int(input())
|
||||||
|
# i=1
|
||||||
|
# micronum=0
|
||||||
|
# sum = 0
|
||||||
|
#
|
||||||
|
# print (i-1, sum)
|
||||||
|
|
||||||
|
N = int(input())
|
||||||
|
s = 0
|
||||||
|
k = 0
|
||||||
|
while N > 0:
|
||||||
|
d = N % 10
|
||||||
|
s += d
|
||||||
|
k += 1
|
||||||
|
N //= 10
|
||||||
|
print("Количество цифр:", k)
|
||||||
|
print("Сумма цифр:", s)
|
||||||
15
labPython/lab2/task3.py
Executable file
15
labPython/lab2/task3.py
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
while True:
|
||||||
|
comp = random.randint(1, 3)
|
||||||
|
user = int(input("1 - камень, 2 - ножницы, 3 - бумага: "))
|
||||||
|
|
||||||
|
if comp == user:
|
||||||
|
print("Ничья, попробуйте снова!")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (user == 1 and comp == 2) or (user == 2 and comp == 3) or (user == 3 and comp == 1):
|
||||||
|
print("Вы выиграли!", comp)
|
||||||
|
else:
|
||||||
|
print("Компьютер выиграл!", comp)
|
||||||
|
break
|
||||||
16
labPython/lab2/task6.py
Executable file
16
labPython/lab2/task6.py
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
print("введите точность и коэффициент")
|
||||||
|
from math import atan
|
||||||
|
T = int(input())
|
||||||
|
x = float(input())
|
||||||
|
count = 0
|
||||||
|
num = 0
|
||||||
|
for i in range(1, T, 2):
|
||||||
|
count += 1
|
||||||
|
if count%2 == 1:
|
||||||
|
num += (x**i)/i
|
||||||
|
else:
|
||||||
|
num -= (x**i)/i
|
||||||
|
|
||||||
|
print(atan(x))
|
||||||
|
print(f"Число arctng(x) с точностью {T}: {num}")
|
||||||
|
|
||||||
277
labPython/lab2/windows.py
Executable file
277
labPython/lab2/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()
|
||||||
8
labPython/lab20/maze.txt
Normal file
8
labPython/lab20/maze.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
M
|
||||||
|
|
||||||
|
M M M
|
||||||
|
M M M
|
||||||
|
M M M
|
||||||
|
MM
|
||||||
|
MMM MMMM
|
||||||
|
|
||||||
65
labPython/lab20/task_1.py
Normal file
65
labPython/lab20/task_1.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
def create_file():
|
||||||
|
n = random.randint(5, 10)
|
||||||
|
maze = []
|
||||||
|
for _ in range(n):
|
||||||
|
row = "".join(["M" if random.random() < 0.3 else " " for _ in range(n)])
|
||||||
|
maze.append(row)
|
||||||
|
with open("maze.txt", "w") as f:
|
||||||
|
for row in maze:
|
||||||
|
f.write(row + "\n")
|
||||||
|
return n
|
||||||
|
|
||||||
|
|
||||||
|
def read_maze():
|
||||||
|
with open("maze.txt") as f:
|
||||||
|
maze = [list(line.rstrip("\n")) for line in f]
|
||||||
|
return maze
|
||||||
|
|
||||||
|
|
||||||
|
def solve(maze, x, y, xc, yc, visited, length, best):
|
||||||
|
n = len(maze)
|
||||||
|
if x < 0 or y < 0 or x >= n or y >= n:
|
||||||
|
return
|
||||||
|
if maze[x][y] == "M" or visited[x][y]:
|
||||||
|
return
|
||||||
|
if length >= best[0]:
|
||||||
|
return
|
||||||
|
if x == xc and y == yc:
|
||||||
|
best[0] = min(best[0], length)
|
||||||
|
return
|
||||||
|
visited[x][y] = True
|
||||||
|
solve(maze, x + 1, y, xc, yc, visited, length + 1, best)
|
||||||
|
solve(maze, x - 1, y, xc, yc, visited, length + 1, best)
|
||||||
|
solve(maze, x, y + 1, xc, yc, visited, length + 1, best)
|
||||||
|
solve(maze, x, y - 1, xc, yc, visited, length + 1, best)
|
||||||
|
visited[x][y] = False
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("\n1 - создать лабиринт\n2 - решить\n0 - выход")
|
||||||
|
try:
|
||||||
|
c = input("Выбор: ")
|
||||||
|
if c == "1":
|
||||||
|
n = create_file()
|
||||||
|
print("Файл создан. Размер:", n)
|
||||||
|
elif c == "2":
|
||||||
|
maze = read_maze()
|
||||||
|
n = len(maze)
|
||||||
|
x = int(input("Старт X: "))
|
||||||
|
y = int(input("Старт Y: "))
|
||||||
|
xc = int(input("Сыр X: "))
|
||||||
|
yc = int(input("Сыр Y: "))
|
||||||
|
visited = [[False] * n for _ in range(n)]
|
||||||
|
best = [10**9]
|
||||||
|
solve(maze, x, y, xc, yc, visited, 0, best)
|
||||||
|
if best[0] == 10**9:
|
||||||
|
print("Путь не найден")
|
||||||
|
else:
|
||||||
|
print("Кратчайший путь:", best[0])
|
||||||
|
elif c == "0":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
37
labPython/lab20/task_2.py
Normal file
37
labPython/lab20/task_2.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
print("task: 6r\nВставка + и - между цифрами для получения числа N")
|
||||||
|
|
||||||
|
|
||||||
|
def generate(s, pos, expr, target, results):
|
||||||
|
if pos == len(s):
|
||||||
|
try:
|
||||||
|
if eval(expr) == target:
|
||||||
|
results.append(expr + "=" + str(target))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
generate(s, pos + 1, expr + "+" + s[pos], target, results)
|
||||||
|
generate(s, pos + 1, expr + "-" + s[pos], target, results)
|
||||||
|
generate(s, pos + 1, expr + s[pos], target, results)
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("\n1 - решить\n0 - выход")
|
||||||
|
try:
|
||||||
|
c = input("Выбор: ")
|
||||||
|
if c == "1":
|
||||||
|
s, target = input("Введите число и N: ").split()
|
||||||
|
target = int(target)
|
||||||
|
results = []
|
||||||
|
generate(s, 1, s[0], target, results)
|
||||||
|
with open("result.txt", "w") as f:
|
||||||
|
if results:
|
||||||
|
for r in results:
|
||||||
|
print(r)
|
||||||
|
f.write(r + "\n")
|
||||||
|
else:
|
||||||
|
print("Решение не существует")
|
||||||
|
f.write("Решение не существует")
|
||||||
|
elif c == "0":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("Ошибка ввода")
|
||||||
14
labPython/lab3/TextFile13.py
Executable file
14
labPython/lab3/TextFile13.py
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
def sum(A:int)->int:
|
||||||
|
A = A * (1 - 2 * (A < 0))
|
||||||
|
# A=abs(A)
|
||||||
|
if A//10 > 0:
|
||||||
|
return A%10 + sum(A//10)
|
||||||
|
else:
|
||||||
|
return A
|
||||||
|
|
||||||
|
num_end = int(input())
|
||||||
|
num_multiply = int(input())
|
||||||
|
with open("e.txt", "w") as file:
|
||||||
|
for i in range(2, num_end+1):
|
||||||
|
if sum(i) == sum(i*num_multiply):
|
||||||
|
file.write(f"{i}\n")
|
||||||
11
labPython/lab3/TextFile8.py
Executable file
11
labPython/lab3/TextFile8.py
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
with open("d.txt", "r") as file:
|
||||||
|
maxX = 0
|
||||||
|
minX = int(file.readline().replace("\n", ""))
|
||||||
|
for x in file:
|
||||||
|
x = int(x.replace("\n", ""))
|
||||||
|
if maxX < x:
|
||||||
|
maxX = x
|
||||||
|
if minX > x:
|
||||||
|
minX = x
|
||||||
|
|
||||||
|
print(f"max: {maxX}, min: {minX}, calculate: {maxX - minX}")
|
||||||
6
labPython/lab3/b.txt
Executable file
6
labPython/lab3/b.txt
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
-1
|
||||||
|
1
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
-1
|
||||||
|
1
|
||||||
25
labPython/lab3/d.txt
Executable file
25
labPython/lab3/d.txt
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
1
|
||||||
|
1
|
||||||
|
3
|
||||||
|
5
|
||||||
|
13
|
||||||
|
21
|
||||||
|
55
|
||||||
|
89
|
||||||
|
233
|
||||||
|
377
|
||||||
|
987
|
||||||
|
1597
|
||||||
|
4181
|
||||||
|
6765
|
||||||
|
1771
|
||||||
|
28657
|
||||||
|
75025
|
||||||
|
121393
|
||||||
|
317811
|
||||||
|
514229
|
||||||
|
1346269
|
||||||
|
2178309
|
||||||
|
5702887
|
||||||
|
9227465
|
||||||
|
24157817
|
||||||
75
labPython/lab3/e.txt
Executable file
75
labPython/lab3/e.txt
Executable file
@@ -0,0 +1,75 @@
|
|||||||
|
9
|
||||||
|
18
|
||||||
|
27
|
||||||
|
36
|
||||||
|
45
|
||||||
|
54
|
||||||
|
72
|
||||||
|
81
|
||||||
|
90
|
||||||
|
99
|
||||||
|
108
|
||||||
|
117
|
||||||
|
135
|
||||||
|
144
|
||||||
|
171
|
||||||
|
180
|
||||||
|
189
|
||||||
|
198
|
||||||
|
207
|
||||||
|
234
|
||||||
|
270
|
||||||
|
279
|
||||||
|
288
|
||||||
|
297
|
||||||
|
342
|
||||||
|
351
|
||||||
|
360
|
||||||
|
396
|
||||||
|
405
|
||||||
|
414
|
||||||
|
441
|
||||||
|
450
|
||||||
|
459
|
||||||
|
486
|
||||||
|
495
|
||||||
|
504
|
||||||
|
540
|
||||||
|
549
|
||||||
|
558
|
||||||
|
576
|
||||||
|
585
|
||||||
|
594
|
||||||
|
639
|
||||||
|
648
|
||||||
|
657
|
||||||
|
693
|
||||||
|
702
|
||||||
|
711
|
||||||
|
720
|
||||||
|
729
|
||||||
|
756
|
||||||
|
765
|
||||||
|
783
|
||||||
|
792
|
||||||
|
801
|
||||||
|
810
|
||||||
|
819
|
||||||
|
828
|
||||||
|
846
|
||||||
|
855
|
||||||
|
864
|
||||||
|
873
|
||||||
|
882
|
||||||
|
891
|
||||||
|
900
|
||||||
|
909
|
||||||
|
918
|
||||||
|
927
|
||||||
|
936
|
||||||
|
945
|
||||||
|
954
|
||||||
|
972
|
||||||
|
981
|
||||||
|
990
|
||||||
|
999
|
||||||
16
labPython/lab3/main.py
Executable file
16
labPython/lab3/main.py
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
# maxNum = 0
|
||||||
|
# file = [1, 2, 2, 2, -10000, 52, 9999, 32, 12]
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# for i in file:
|
||||||
|
# delta = maxNum - i
|
||||||
|
# delta = delta * (1 - 2 * (delta < 0))
|
||||||
|
# sum = maxNum + i
|
||||||
|
#
|
||||||
|
# maxNum = (sum - delta) / 2 + delta
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# print (maxNum)
|
||||||
|
|
||||||
|
print(1%1)
|
||||||
11
labPython/lab3/textfile17.py
Executable file
11
labPython/lab3/textfile17.py
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
with open("b.txt", "r") as file:
|
||||||
|
num_this = 0
|
||||||
|
is_subsequence = True
|
||||||
|
lines = file.readlines()
|
||||||
|
num_prev = int(lines[0].replace("\n", ""))
|
||||||
|
for i in range(1, len(lines)):
|
||||||
|
num_this = int(lines[i].replace("\n", ""))
|
||||||
|
is_subsequence = ((num_prev>0)and(num_this<0))or((num_prev<0)and(num_this>0))and(is_subsequence)
|
||||||
|
num_prev = int(lines[i].replace("\n", ""))
|
||||||
|
|
||||||
|
print(is_subsequence)
|
||||||
19
labPython/lab3/textfile4.py
Executable file
19
labPython/lab3/textfile4.py
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
def fibonachi(num_for_stop:int) -> int:
|
||||||
|
if num_for_stop <= 0:
|
||||||
|
return 0
|
||||||
|
elif num_for_stop == 1:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return fibonachi(num_for_stop-2) + fibonachi(num_for_stop-1)
|
||||||
|
|
||||||
|
num_end = int(input())
|
||||||
|
|
||||||
|
with open("d.txt", "w") as file:
|
||||||
|
count = 0
|
||||||
|
i=0
|
||||||
|
while count < num_end:
|
||||||
|
num_fib = fibonachi(i)
|
||||||
|
if num_fib%2 == 1:
|
||||||
|
file.write(f"{num_fib}\n")
|
||||||
|
count+=1
|
||||||
|
i +=1
|
||||||
24
labPython/lab4/MinMax27.py
Executable file
24
labPython/lab4/MinMax27.py
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
nBit = int(input("Введите количество элементов N: "))
|
||||||
|
bitArray = [random.randint(0, 1) for _ in range(nBit)]
|
||||||
|
print(bitArray)
|
||||||
|
countLen = 0
|
||||||
|
countIndex = 0
|
||||||
|
bitMax = 0
|
||||||
|
bitMaxIndex = 0
|
||||||
|
for i in range(len(bitArray)):
|
||||||
|
if i < len(bitArray)-1:
|
||||||
|
if bitArray[i] == bitArray[(i+1)]:
|
||||||
|
countLen +=1
|
||||||
|
if countLen > bitMax:
|
||||||
|
bitMax = countLen
|
||||||
|
bitMaxIndex = (i+2) - bitMax
|
||||||
|
# countLen = 0
|
||||||
|
|
||||||
|
else:
|
||||||
|
countLen = 0
|
||||||
|
bitMax += 1
|
||||||
|
|
||||||
|
|
||||||
|
print(bitMax, bitMaxIndex)
|
||||||
44
labPython/lab4/Modul2.py
Executable file
44
labPython/lab4/Modul2.py
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
from random import randint
|
||||||
|
def Gen():
|
||||||
|
cartRandAndPorc = (randint(100, 1000), randint(1, 100))
|
||||||
|
return cartRandAndPorc
|
||||||
|
|
||||||
|
def Question(procent):
|
||||||
|
try:
|
||||||
|
return int(input(f"{procent[1]} процен(т\ов) от числа {procent[0]}: "))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
def Proverka(answer, answerTrue):
|
||||||
|
answerTrue = int((answerTrue[0]/100)*answerTrue[1])
|
||||||
|
if answer == answerTrue:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def Ball(trulest, qCount)->int:
|
||||||
|
point = 100//qCount
|
||||||
|
if trulest == 1:
|
||||||
|
return point
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def Mark(points):
|
||||||
|
if points <= 40:
|
||||||
|
return 2
|
||||||
|
elif points <= 60:
|
||||||
|
return 3
|
||||||
|
elif points <= 80:
|
||||||
|
return 4
|
||||||
|
elif points > 80:
|
||||||
|
return 5
|
||||||
|
|
||||||
|
points = 0
|
||||||
|
qCount = int(input("Колличество вопросов: "))
|
||||||
|
for i in range(1, qCount+1):
|
||||||
|
|
||||||
|
print("Вопрос ", i)
|
||||||
|
gen = Gen()
|
||||||
|
answer = Question(gen)
|
||||||
|
points += Ball(Proverka(answer, gen), qCount)
|
||||||
|
|
||||||
|
print(f"Ваша оценка {Mark(points)}, общее число баллов: {points}")
|
||||||
6
labPython/lab4/Reccur17.py
Executable file
6
labPython/lab4/Reccur17.py
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
def n_chlen(num_end):
|
||||||
|
if num_end <= 1:
|
||||||
|
return 2
|
||||||
|
else:
|
||||||
|
return (num_end+1)/num_end + n_chlen(num_end-1)
|
||||||
|
print(n_chlen(2))
|
||||||
6
labPython/lab4/Reccur2.py
Executable file
6
labPython/lab4/Reccur2.py
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
def maxNum(num_end:int) -> int:
|
||||||
|
if num_end < 1:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return num_end%10 + maxNum(num_end//10)
|
||||||
|
print(maxNum(0))
|
||||||
10
labPython/lab5/DArray14.py
Executable file
10
labPython/lab5/DArray14.py
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
from random import randint
|
||||||
|
from MatrixMethods import initnxnMatrix, printMatrix, divideEvenColumnsMainDiagonal
|
||||||
|
|
||||||
|
x = int(input("Введите размерность матрицы: "))
|
||||||
|
Array = initnxnMatrix(x)
|
||||||
|
print("Матрица раньше:")
|
||||||
|
printMatrix(Array)
|
||||||
|
Array = divideEvenColumnsMainDiagonal(Array)
|
||||||
|
print("Матрица сейчас:")
|
||||||
|
printMatrix(Array)
|
||||||
15
labPython/lab5/DArray2.py
Executable file
15
labPython/lab5/DArray2.py
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
from MatrixMethods import printMatrix, transDiagonalMatrix
|
||||||
|
|
||||||
|
from random import randint
|
||||||
|
n = (int(input("введите размеров массивов: "))%11)
|
||||||
|
Matrix = [[randint(1, 100) for _ in range(n)] for _ in range(n)]
|
||||||
|
print("Mатрица до изменений:\n\n")
|
||||||
|
printMatrix(Matrix)
|
||||||
|
print("\n\n")
|
||||||
|
for index, stroke in enumerate(Matrix):
|
||||||
|
Matrix[index] = transDiagonalMatrix(stroke, index )
|
||||||
|
|
||||||
|
print("Mатрица после изменений:\n\n")
|
||||||
|
printMatrix(Matrix)
|
||||||
|
print("\n\n")
|
||||||
|
|
||||||
32
labPython/lab5/MatrixMethods.py
Executable file
32
labPython/lab5/MatrixMethods.py
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
from random import randint
|
||||||
|
|
||||||
|
def initnxnMatrix(count:int)->list[list]:
|
||||||
|
Array = [[randint(1, 100) for _ in range(count)] for _ in range(count)]
|
||||||
|
return Array
|
||||||
|
|
||||||
|
def printMatrix(Array:list[list])->None:
|
||||||
|
for i in range(len(Array)+1):
|
||||||
|
print(f"{i}\t", end="")
|
||||||
|
print("")
|
||||||
|
for index in range(len(Array)):
|
||||||
|
print(f"{index+1}\t", end="")
|
||||||
|
for value in Array[index]:
|
||||||
|
print(f"{value}\t", end="")
|
||||||
|
print("")
|
||||||
|
|
||||||
|
def transDiagonalMatrix(Array:list[list], i:int)->list:
|
||||||
|
if Array[i] != Array[-(i+1)]:
|
||||||
|
Array[i] += Array[-(i+1)]
|
||||||
|
Array[-(i+1)] = Array[i] - Array[-(i+1)]
|
||||||
|
Array[i] = Array[i] - Array[-(i+1)]
|
||||||
|
return Array
|
||||||
|
|
||||||
|
def divideEvenColumnsMainDiagonal(Array:list[list])->list[list]:
|
||||||
|
mainDiagonal = 0
|
||||||
|
for index, element in enumerate(Array):
|
||||||
|
mainDiagonal += element[index]
|
||||||
|
for elementIndex, element in enumerate(Array):
|
||||||
|
for index in range(len(element)):
|
||||||
|
if (index + 1)%2==0:
|
||||||
|
Array[elementIndex][index] //= mainDiagonal
|
||||||
|
return Array
|
||||||
21
labPython/lab5/Slov14.py
Executable file
21
labPython/lab5/Slov14.py
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
candies = {
|
||||||
|
"Шоколадные": {"price": 150, "shelf_life": "12 месяцев", "shops": [1, 3, 5]},
|
||||||
|
"Карамель": {"price": 80, "shelf_life": "6 месяцев", "shops": [2, 4]},
|
||||||
|
"Трюфели": {"price": 150, "shelf_life": "18 месяцев", "shops": [1, 2, 3]},
|
||||||
|
"Мармелад": {"price": 120, "shelf_life": "9 месяцев", "shops": [2, 5]},
|
||||||
|
"Ириски": {"price": 950, "shelf_life": "8 месяцев", "shops": [1, 3, 4]},
|
||||||
|
"Вафли": {"price": 1800, "shelf_life": "10 месяцев", "shops": [3, 4, 5]},
|
||||||
|
"Пряники": {"price": 110, "shelf_life": "7 месяцев", "shops": [1, 2]}
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, info in candies.items():
|
||||||
|
if 100 <= info["price"] <= 200:
|
||||||
|
print(f"{name}:")
|
||||||
|
print(f" Срок годности: {info['shelf_life']}")
|
||||||
|
shops_str = ""
|
||||||
|
for i in range(len(info['shops'])):
|
||||||
|
if i > 0:
|
||||||
|
shops_str += ", "
|
||||||
|
shops_str += str(info['shops'][i])
|
||||||
|
print(f" Магазины: {shops_str}")
|
||||||
|
|
||||||
12
labPython/lab5/Slov32.py
Executable file
12
labPython/lab5/Slov32.py
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
books = [
|
||||||
|
{"author": "Толстой", "title": "Война и мир", "year": 1869},
|
||||||
|
{"author": "Пушкин", "title": "Евгений Онегин", "year": 1833},
|
||||||
|
{"author": "Кнут", "title": "Искусство программирования", "year": 1968},
|
||||||
|
{"author": "Таненбаум", "title": "Архитектура компьютера", "year": 1976},
|
||||||
|
{"author": "Столл", "title": "Введение в информатику", "year": 1985},
|
||||||
|
{"author": "Уоррен", "title": "Алгоритмические трюки для программистов", "year": 2002},
|
||||||
|
{"author": "Кнут", "title": "Конкретная математика", "year": 1994},
|
||||||
|
{"author": "Столл", "title": "Основы информатики", "year": 1970},
|
||||||
|
{"author": "Пушкин", "title": "Руслан и Людмила", "year": 1820},
|
||||||
|
{"author": "Таненбаум", "title": "Современные операционные системы", "year": 1992},
|
||||||
|
]
|
||||||
12
labPython/lab5/Slov9.py
Executable file
12
labPython/lab5/Slov9.py
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
string = input()
|
||||||
|
count = {}
|
||||||
|
result = ""
|
||||||
|
|
||||||
|
for char in string:
|
||||||
|
if char not in count:
|
||||||
|
count[char] = 0
|
||||||
|
else:
|
||||||
|
count[char] += 1
|
||||||
|
result += f"{char}_{count[char]}"
|
||||||
|
|
||||||
|
print(result)
|
||||||
20
labPython/lab5/Spis12.py
Executable file
20
labPython/lab5/Spis12.py
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
ArrayStatic = (1, 2, 34, 53, 20, 10)
|
||||||
|
maxNum = 0
|
||||||
|
maxIndex = 0
|
||||||
|
minNum = ArrayStatic[0]
|
||||||
|
minIndex = 0
|
||||||
|
|
||||||
|
for index in range(0, len(ArrayStatic)):
|
||||||
|
if maxNum < ArrayStatic[index]:
|
||||||
|
maxNum = ArrayStatic[index]
|
||||||
|
maxIndex = index
|
||||||
|
if minNum > ArrayStatic[index]:
|
||||||
|
minNum = ArrayStatic[index]
|
||||||
|
minIndex = index
|
||||||
|
|
||||||
|
print(ArrayStatic)
|
||||||
|
ArrayStatic = list(ArrayStatic)
|
||||||
|
ArrayStatic[maxIndex] = minNum
|
||||||
|
ArrayStatic[minIndex] = maxNum
|
||||||
|
ArrayStatic = tuple(ArrayStatic)
|
||||||
|
print(ArrayStatic)
|
||||||
59
labPython/lab5/Spis22.py
Executable file
59
labPython/lab5/Spis22.py
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
def evaluate(expr: str) -> int:
|
||||||
|
expr = expr.replace(" ", "")
|
||||||
|
pos = 0
|
||||||
|
|
||||||
|
def number():
|
||||||
|
nonlocal pos
|
||||||
|
start = pos
|
||||||
|
if pos < len(expr) and expr[pos] in '+-':
|
||||||
|
pos += 1
|
||||||
|
while pos < len(expr) and expr[pos].isdigit():
|
||||||
|
pos += 1
|
||||||
|
return int(expr[start:pos])
|
||||||
|
|
||||||
|
def factor():
|
||||||
|
nonlocal pos
|
||||||
|
if pos < len(expr) and expr[pos] == '(':
|
||||||
|
pos += 1
|
||||||
|
result = expression()
|
||||||
|
if pos >= len(expr) or expr[pos] != ')':
|
||||||
|
raise ValueError
|
||||||
|
pos += 1
|
||||||
|
return result
|
||||||
|
return number()
|
||||||
|
|
||||||
|
def term():
|
||||||
|
nonlocal pos
|
||||||
|
result = factor()
|
||||||
|
while pos < len(expr) and expr[pos] in '*/':
|
||||||
|
op = expr[pos]
|
||||||
|
pos += 1
|
||||||
|
if op == '*':
|
||||||
|
result *= factor()
|
||||||
|
else:
|
||||||
|
num = factor()
|
||||||
|
if num == 0:
|
||||||
|
raise ValueError
|
||||||
|
result //= num
|
||||||
|
return result
|
||||||
|
|
||||||
|
def expression():
|
||||||
|
nonlocal pos
|
||||||
|
result = term()
|
||||||
|
while pos < len(expr) and expr[pos] in '+-':
|
||||||
|
op = expr[pos]
|
||||||
|
pos += 1
|
||||||
|
if op == '+':
|
||||||
|
result += term()
|
||||||
|
else:
|
||||||
|
result -= term()
|
||||||
|
return result
|
||||||
|
|
||||||
|
result = expression()
|
||||||
|
if pos < len(expr):
|
||||||
|
raise ValueError
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
expr = input()
|
||||||
|
print(evaluate(expr))
|
||||||
BIN
labPython/lab5/__pycache__/ArrayMetods.cpython-313.pyc
Executable file
BIN
labPython/lab5/__pycache__/ArrayMetods.cpython-313.pyc
Executable file
Binary file not shown.
BIN
labPython/lab5/__pycache__/MatrixMethods.cpython-313.pyc
Executable file
BIN
labPython/lab5/__pycache__/MatrixMethods.cpython-313.pyc
Executable file
Binary file not shown.
14
labPython/lab6/Graf13.py
Executable file
14
labPython/lab6/Graf13.py
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
import numpy as nu
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def xycomlete(x):
|
||||||
|
y = nu.sin(5 * x) * nu.cos(x)
|
||||||
|
return y
|
||||||
|
|
||||||
|
|
||||||
|
ArrayX = nu.arange(0, 3, 0.01)
|
||||||
|
ArrayY = xycomlete(ArrayX)
|
||||||
|
|
||||||
|
plt.plot(ArrayX, ArrayY)
|
||||||
|
plt.show()
|
||||||
13
labPython/lab6/Matr7.py
Executable file
13
labPython/lab6/Matr7.py
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
from numpy import array, full, fill_diagonal, fliplr
|
||||||
|
|
||||||
|
count = int(input("введите число строк в матрице (nxn): "))
|
||||||
|
|
||||||
|
if count%2!=1:
|
||||||
|
count+=1
|
||||||
|
Array = full((count, count), ".")
|
||||||
|
new_diag = ["*" for _ in range(count)]
|
||||||
|
fill_diagonal(Array, new_diag)
|
||||||
|
Array = fliplr(Array)
|
||||||
|
fill_diagonal(Array, new_diag)
|
||||||
|
Array = fliplr(Array)
|
||||||
|
print (Array)
|
||||||
4
labPython/lab6/Slice12.py
Executable file
4
labPython/lab6/Slice12.py
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
from numpy import random
|
||||||
|
|
||||||
|
arrayTriple = random.randint(0, 47, (6, 86, 8))
|
||||||
|
print(arrayTriple)
|
||||||
7
labPython/lab6/task5_5_1.py
Executable file
7
labPython/lab6/task5_5_1.py
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
plt.pie(
|
||||||
|
[10, 8, 6, 4, 2],
|
||||||
|
labels=["Москва", "Санкт-Петербург", "Сочи", "Казань", "Калининград"],
|
||||||
|
)
|
||||||
|
plt.show()
|
||||||
12
labPython/lab6/task5_5_2.py
Executable file
12
labPython/lab6/task5_5_2.py
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
num_points = 1200
|
||||||
|
|
||||||
|
x = np.random.uniform(-5.2, 20.7, num_points)
|
||||||
|
y = np.random.uniform(-5.2, 20.7, num_points)
|
||||||
|
|
||||||
|
plt.figure(figsize=(8, 8))
|
||||||
|
plt.scatter(x, y, color="green", s=10, alpha=0.6)
|
||||||
|
plt.grid(True)
|
||||||
|
plt.show()
|
||||||
66
labPython/lab7/BinSearch_2.py
Executable file
66
labPython/lab7/BinSearch_2.py
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
def find_min_radius(feasible, eps=1e-6, max_radius=None):
|
||||||
|
if max_radius is None:
|
||||||
|
high_bound = 1.0
|
||||||
|
while not feasible(high_bound):
|
||||||
|
high_bound *= 2
|
||||||
|
if high_bound > 1e10:
|
||||||
|
raise ValueError(
|
||||||
|
"Не удалось найти верхнюю границу. Возможно, feasible всегда возвращает False."
|
||||||
|
)
|
||||||
|
low = 0.0
|
||||||
|
high = high_bound
|
||||||
|
else:
|
||||||
|
low = 0.0
|
||||||
|
high = max_radius
|
||||||
|
|
||||||
|
while high - low > eps:
|
||||||
|
mid = (low + high) / 2.0
|
||||||
|
|
||||||
|
if feasible(mid):
|
||||||
|
high = mid
|
||||||
|
else:
|
||||||
|
low = mid
|
||||||
|
|
||||||
|
return high
|
||||||
|
|
||||||
|
|
||||||
|
def can_cover(points, m, r):
|
||||||
|
if not points:
|
||||||
|
return True
|
||||||
|
|
||||||
|
used_circles = 0
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
while i < len(points):
|
||||||
|
circle_center = points[i] + r
|
||||||
|
circle_right = circle_center + r
|
||||||
|
|
||||||
|
used_circles += 1
|
||||||
|
if used_circles > m:
|
||||||
|
return False
|
||||||
|
|
||||||
|
while i < len(points) and points[i] <= circle_right:
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("Введите N и M через пробел:")
|
||||||
|
n, m = map(int, input("> ").split())
|
||||||
|
|
||||||
|
print(f"Введите {n} координат точек (по одной на строке):")
|
||||||
|
points = []
|
||||||
|
for _ in range(n):
|
||||||
|
point = float(input().strip())
|
||||||
|
points.append(point)
|
||||||
|
|
||||||
|
points.sort()
|
||||||
|
|
||||||
|
def feasible(r):
|
||||||
|
return can_cover(points, m, r)
|
||||||
|
|
||||||
|
eps = 1e-6
|
||||||
|
result = find_min_radius(feasible, eps=eps)
|
||||||
|
|
||||||
|
print(f"Минимальный радиус: {result:.6f}")
|
||||||
BIN
labPython/lab7/__pycache__/sort2.cpython-313.pyc
Executable file
BIN
labPython/lab7/__pycache__/sort2.cpython-313.pyc
Executable file
Binary file not shown.
BIN
labPython/lab7/__pycache__/sort_methods.cpython-313.pyc
Executable file
BIN
labPython/lab7/__pycache__/sort_methods.cpython-313.pyc
Executable file
Binary file not shown.
BIN
labPython/lab7/__pycache__/sort_methods.cpython-314.pyc
Executable file
BIN
labPython/lab7/__pycache__/sort_methods.cpython-314.pyc
Executable file
Binary file not shown.
30
labPython/lab7/input.txt
Executable file
30
labPython/lab7/input.txt
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
37
|
||||||
|
-44
|
||||||
|
40
|
||||||
|
93
|
||||||
|
76
|
||||||
|
-73
|
||||||
|
-80
|
||||||
|
-11
|
||||||
|
48
|
||||||
|
-67
|
||||||
|
1
|
||||||
|
-46
|
||||||
|
-58
|
||||||
|
-85
|
||||||
|
67
|
||||||
|
96
|
||||||
|
8
|
||||||
|
36
|
||||||
|
-88
|
||||||
|
-21
|
||||||
|
54
|
||||||
|
-2
|
||||||
|
21
|
||||||
|
-25
|
||||||
|
-48
|
||||||
|
71
|
||||||
|
-3
|
||||||
|
3
|
||||||
|
71
|
||||||
|
-55
|
||||||
30
labPython/lab7/output.txt
Executable file
30
labPython/lab7/output.txt
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
-88
|
||||||
|
-85
|
||||||
|
-80
|
||||||
|
-73
|
||||||
|
-67
|
||||||
|
-58
|
||||||
|
-55
|
||||||
|
-48
|
||||||
|
-46
|
||||||
|
-44
|
||||||
|
-25
|
||||||
|
-21
|
||||||
|
-11
|
||||||
|
-3
|
||||||
|
-2
|
||||||
|
1
|
||||||
|
3
|
||||||
|
8
|
||||||
|
21
|
||||||
|
36
|
||||||
|
37
|
||||||
|
40
|
||||||
|
48
|
||||||
|
54
|
||||||
|
67
|
||||||
|
71
|
||||||
|
71
|
||||||
|
76
|
||||||
|
93
|
||||||
|
96
|
||||||
21
labPython/lab7/sort2.py
Executable file
21
labPython/lab7/sort2.py
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
from os import replace
|
||||||
|
import sort_methods
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
array = [randint(-100, 100) for _ in range(30)]
|
||||||
|
with open("input.txt", "w") as inputFile:
|
||||||
|
for element in array:
|
||||||
|
inputFile.write(f"{element}\n")
|
||||||
|
listOfNumber = []
|
||||||
|
with open("input.txt", "r") as inputFile:
|
||||||
|
for string in inputFile:
|
||||||
|
listOfNumber.append(int(string.replace("\n", "")))
|
||||||
|
print(listOfNumber)
|
||||||
|
listOfNumber = sort_methods.bubble_sort(listOfNumber)
|
||||||
|
|
||||||
|
with open("output.txt", "w") as outputFile:
|
||||||
|
for element in listOfNumber:
|
||||||
|
outputFile.write(f"{element}\n")
|
||||||
|
|
||||||
|
print("Пузырьковая сортировка")
|
||||||
|
print("сложность сортировки O(n^2)")
|
||||||
32
labPython/lab7/sort_methods.py
Executable file
32
labPython/lab7/sort_methods.py
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
def printSortedList(list: list, sortedCount: int) -> None:
|
||||||
|
text = ""
|
||||||
|
for index in range(len(list)):
|
||||||
|
if index != sortedCount:
|
||||||
|
text += f"{list[index]}, "
|
||||||
|
|
||||||
|
else:
|
||||||
|
if sortedCount != 0:
|
||||||
|
text += f"{list[index]}|"
|
||||||
|
else:
|
||||||
|
text += f"отсортированый массив => {list[index]}, "
|
||||||
|
print(text)
|
||||||
|
|
||||||
|
|
||||||
|
def bubble_sort(list: list) -> list:
|
||||||
|
count = 1
|
||||||
|
sortedCount = len(list) - 1
|
||||||
|
while count != 0:
|
||||||
|
count = 0
|
||||||
|
for index in range(len(list)):
|
||||||
|
if index < len(list) - 1:
|
||||||
|
if list[index] > list[index + 1]:
|
||||||
|
list[index] += list[index + 1]
|
||||||
|
list[index + 1] = list[index] - list[index + 1]
|
||||||
|
list[index] = list[index] - list[index + 1]
|
||||||
|
count += 1
|
||||||
|
if count != 0:
|
||||||
|
sortedCount -= 1
|
||||||
|
else:
|
||||||
|
sortedCount = 0
|
||||||
|
printSortedList(list, sortedCount)
|
||||||
|
return list
|
||||||
1
labPython/project_ind/individual_project_realtor
Submodule
1
labPython/project_ind/individual_project_realtor
Submodule
Submodule labPython/project_ind/individual_project_realtor added at e2ec3f70c3
Reference in New Issue
Block a user