Advertisement
Roman9234

Untitled

Feb 9th, 2024
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. @get_connection
  2. def add_teacher(cur=None):
  3.     first_name = ""
  4.     while not check_field(first_name):
  5.         first_name = input("Введите имя учителя: ").capitalize()
  6.     last_name = ""
  7.     while not check_field(last_name):
  8.         last_name = input("Введите фамилию учителя: ").capitalize()
  9.     pater_name = ""
  10.     while not check_field(pater_name):
  11.         pater_name = input("Введите отчество учителя: ").capitalize()
  12.    
  13.     gender = ""
  14.     while gender not in ["м", "ж"]:
  15.         gender = input("Выберите пол (м/ж): ")
  16.        
  17.     phone_number = ""
  18.     while len(phone_number) < 5 and  not phone_number.isdigit():
  19.         phone_number = input("Введите номер телефона без пробелов: ")
  20.    
  21.     cur.execute("SELECT COUNT(*) FROM teachers")
  22.     id = cur.fetchone()[0] + 1
  23.     try:
  24.         cur.execute("INSERT into teachers values(%d, '%s','%s','%s','%s','%s')"%(
  25.             id, first_name, last_name, pater_name, gender, phone_number
  26.         ))
  27.         print("Успешно добавлен новый преподаватель")
  28.     except:
  29.         print("Что-то не получилось")
  30.  
  31.  
  32. def add_subject(cur=None):
  33.     name = ""
  34.     while not check_field(name):
  35.         name = input('Введите название предмета: ')
  36.     cur.execute('SELECT COUNT(*) FROM subjects')
  37.     id = cur.fetchone()[0] + 1
  38.     try:
  39.         cur.execute("INSERT INTO subjects VALUES (%d, '%s');" % (
  40.             id, name
  41.         ))
  42.         print('Успешно добавлена новая запись!')
  43.     except:
  44.         print('Что-то не получилось')
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement