+ 1

как сгенерировать 1000000 записей, . Возраст, стипендия, группа и год окончания генерируются случайным образом. Допускается испо

# в этом коде. empty_student = {'name': '', 'second_name': '', 'group': '', 'age': 0, 'year_final': 0, 'salary': 0 } print_order = ['name', 'second_name', 'age', 'group', 'year_final', 'salary' ] students = [] def add_student(): students.append(empty_student.copy()) current_student = students[-1] for key in current_student: current_student[key] = input('Enter ' + key + ':') if type(empty_student[key]) == type(1): current_student[key] = int(current_student[key]) def remove_student(): print('Remove student') name = input('Enter name for deletion:') second_name = input('Enter second name for deletion:') age = input('Enter age for deletion:') found_student = None for student in students: if (name == student['name'] and second_name == student['second_name'] and age == str(student['age'])): found_student = student break if found_student != None: students.remove(found_student) pass def dump_student_database(): f = open('students.db', 'w') f.write(str(students)) f.close() def load_student_database(): f = open('students.db', 'r') global students students = eval(f.readline()) f.close() def print_students(): print('Database has ' + str(len(students)) + ' students') for student in students: print('---------------') for key in print_order: pad = ' ' * (len('second_name') - len(key)) print(key, pad, student[key]) load_student_database() while True: regime = input('Enter mode (1 - add, 2 - remove, 3 - printout):') if regime == '1': add_student() dump_student_database() elif regime == '2': remove_student() dump_student_database() elif regime == '3': print_students() exit()

10th Dec 2018, 9:15 AM
Anonim
1 Resposta
0
Составьте список вариантов и случайным образом выберите один из них: import random ages = [16, 17, 18, 19, 20, 21, 22, 26, 30] age = random.choice(ages)
10th Dec 2018, 6:41 PM
John Wells
John Wells - avatar