import os
import csv
from tkinter import *
import tkinter as tk
import pandas as pd
#переменные
gh = int(0)
rh = int(0)
rm = int(0)
sh = int(0)
mm = int(0)
def close_window():
global n_desk1
global n_ryadov1
global n_file
n_desk1 = n_desk_entry.get()
n_file = n_file_entry.get()
n_ryadov1 = n_ryadov_entry.get()
root.destroy()
root = Tk()
root.title('Расчет рассадки')
root.geometry('600x400+200+100')
n_ryadov_label = Label(root, text = 'Введите кол-во рядов', )
n_ryadov_label.pack(anchor = CENTER)
n_ryadov_entry = Entry(root)
n_ryadov_entry.pack(anchor = CENTER)
n_desk_label = Label(root, text = 'Введите кол-во учеников за партой')
n_desk_label.pack()
n_desk_entry = Entry(root)
n_desk_entry.pack(anchor = CENTER)
n_file_label = Label(root, text = 'Введите название файла')
n_file_label.pack(anchor = CENTER)
n_file_entry = Entry(root)
n_file_entry.pack(anchor = CENTER)
Button = Button(root, text = "Начать" , command =close_window)
Button.pack(anchor = S)
root.mainloop()
n_desk = int(n_desk1)
n_ryadov = int(n_ryadov1)
with open (n_file , 'r') as f:
a = csv.reader(f, delimiter = ';')
s = 0
students = []
for i in a:
s+=1
name , surname , growth, zrenie = i
growth = float(growth)
zrenie = float(zrenie)
if zrenie > 1:
zrenie = 2 - zrenie
students.append((name, surname, float(growth), float(zrenie)))
students.sort(key = lambda x: (x[2]))
students.sort(key = lambda x: (x[3]))
slice = n_ryadov * n_desk
out_list = []
for i in range(0, s, slice):
out_list.append(students[i:i + slice])
print(*out_list, sep = '\n')
name , surname , growth, zrenie = i
[('rq', 'rq', 178.0, -8.0), ('ty', 'ty', 189.0, -4.0)]
[('rt', 'rt', 190.0, -3.0), ('my', 'my', 170.0, -0.3)]
[('js ', 'js', 179.0, 0.3), ('a ', 'a ', 156.0, 0.4)]
[('ra', 'ra', 156.0, 0.8), ('mm ', 'mm', 180.0, 1.0)]
rq rq ty ty
[('rq' 'rq') ('ty''ty')]
[[('rq', 'rq', 178.0, -8.0), ('ty', 'ty', 189.0, -4.0)],
[('rt', 'rt', 190.0, -3.0), ('my', 'my', 170.0, -0.3)],
[('js', 'js', 179.0, 0.3), ('a ', 'a ', 156.0, 0.4)],
[('ra', 'ra', 156.0, 0.8), ('mm ', 'mm', 180.0, 1.0)]]
[[('rq', 'rq'), ('ty', 'ty')],
[('rt', 'rt'), ('my', 'my')],
[('js', 'js'), ('a ', 'a ')],
[('ra', 'ra'), ('mm ', 'mm')]]
it=[[('rq', 'rq', 178.0, -8.0), ('ty', 'ty', 189.0, -4.0)],
[('rt', 'rt', 190.0, -3.0), ('my', 'my', 170.0, -0.3)],
[('js', 'js', 179.0, 0.3), ('a ', 'a ', 156.0, 0.4)],
[('ra', 'ra', 156.0, 0.8), ('mm ', 'mm', 180.0, 1.0)]]
print(it)
ot=[]
for el in it:
ot.append([el[0][0:2],el[1][0:2]])
print(ot)