Help #3199
Closed
YuriiHauss
started this conversation in
General
Help
#3199
Replies: 1 comment
-
Codewars Github is not meant for help with general programming tasks. It's meant to discuss matters related to Codewars platform, the website, its functions, etc. For help with your assignment please visit your favorite homework forum, a code review forum, or you can try your luck asking for help on Codewars Discord. Closing as off-topic. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So below is my code in python for practice, can you tell me some advices to improve my code
import pickle
class University:
def init(self, faculties_names, faculty_info, cathedra_info):
self.faculties = faculties_names
self.faculty_info = faculty_info
self.cathedra_info = cathedra_info
self.cathedra = None
self.options = ["Викладачі", "Студенти"]
self.option = None
self.course1 = []
self.course2 = []
self.course3 = []
self.course4 = []
class Faculty(University):
def init(self, faculty, faculties_names, faculty_info, cathedra_info):
super().init(faculties_names, faculty_info, cathedra_info)
self.faculty = faculty
self.info = None
self.choice_info = None
self.info_choices = ["Декан", "Кафедри", "Спеціальності"]
class Cathedra(University):
def init(self, cathedra, faculties_names, faculty_info, cathedra_info):
super().init(faculties_names, faculty_info, cathedra_info)
self.cathedra = cathedra
self.info = None
self.choice_info = None
self.info_choices = ["Завідувач", "Спеціаліст кафедри", "Студенти", "Викладачі"]
def read(filename):
with open(filename, 'rb') as f:
return pickle.load(f)
university = University(read("faculties.pickle"), read("faculties_info.pickle"), read("cathedras_info.pickle"))
def menu():
options = ["Створити/видалити/редагувати інформацію про факультет/кафедру [конкретного] факультета.",
"Знайти інформацію про студента за ПІБ",
"Знайти інформацію про викладача за ПІБ",
"Вивести інформацію про всіх студентів впорядкованих за курсами.",
"Вивести інформацію про всіх студентів факультета впорядкованих за алфавітом.",
"Вивести інформацію про всіх викладачів факультета впорядкованих за алфавітом.",
"Вивести інформацію про всіх студентів кафедри впорядкованих за курсами",
"Вивести інформацію про всіх студентів кафедри впорядкованих за алфавітом.",
"Вивести інформацію про всіх викладачів кафедри впорядкованих за алфавітом.",
"Вивести інформацію про всіх студентів кафедри вказаного курсу.",
"Вивести інформацію про всіх студентів кафедри вказаного курсу впорядкованих за алфавітом.",
"Зберегти дані програми в локальне сховище.",
"Відновити дані програми з локального сховища.",
"Прочитати дані програми з локального сховища."]
while True:
print("Головне меню:")
show_choices(options)
choice = get_choice(len(options) + 2)
choices = [university.choose_option, university.find_student,
university.find_teacher,
university.display_students_by_courses, university.show_faculty_students_alph,
university.show_faculty_teachers_alph,
university.show_cathedra_stud_sorted_course,
university.show_cathedra_stud_alph, # Треба назви по менше, придумай щось
university.show_cathedra_teachers_alph,
university.show_stud_by_course_cathedra,
university.show_stud_alph_by_cathedra_and_course,
university.save_data,
university.restore_data,
university.read_data]
if choice <= len(choices):
return choiceschoice - 1
else:
break
def get_choice(max_choice):
choice = input(f"Оберіть опцію\n>>> ")
try:
if 1 <= int(choice) <= max_choice:
return int(choice)
else:
print(
f"\nНевірний вибір. Будь ласка, введіть число від 1 до {max_choice}.\n") # Помилки б окремо було б з мега кайфом
return get_choice(max_choice)
except ValueError:
print(f"\nНевірний вибір. Будь ласка, введіть число від 1 до {max_choice}.\n")
return get_choice(max_choice)
def get_info(name, options):
info = input(f"Введіть {name} які хочете додати: ")
if info == str(len(options) + 1):
return menu()
elif info in options:
print("Ця інформація вже збережена, введіть іншу")
return get_info(name, options)
return info
def show_choices(options):
for index, option in enumerate(options):
print(f"{index + 1}. {option}")
print(f"{len(options) + 1}: Вийти в головне меню")
def choose_info(place, place_info, info_choices):
show_choices(place_info[place])
choice_info = get_choice(len(place_info[place]) + 1)
if 1 <= choice_info <= len(info_choices):
info = place_info[place][info_choices[choice_info - 1]]
return info, choice_info
return menu()
def main():
while True:
print("1. Показати головне меню")
print("2. Вийти")
choice = get_choice(2)
if choice == 2:
break
else:
menu()
def choose_from_list(items):
show_choices(items)
index = get_choice(len(items) + 1)
if 1 <= index <= len(items):
return items[index - 1]
return menu()
main()
Beta Was this translation helpful? Give feedback.
All reactions