Python学習者情報管理システム(v 2.0)
4676 ワード
, ,
#
def add_student():
name = input(' :')
age = input(' :')
sex = input(' :')
phone = input(' :')
student = [name,age,sex,phone]
student_list.append(student)
#
def query_student():
# 1.
# 2.
for x in range(0, len(student_list)):
# x ,
student = student_list[x]
name = student[0]
age = student[1]
sex = student[2]
phone = student[3]
print (' %s : %s %s %s %s'%(x,name,age,sex,phone))
#
def update_student():
# , ,
if len(student_list) == 0:
print (' , !')
#
return
# 1.
query_student()
# 2.
num = input(' :')
# 3.
num = int(num)
# 4.
while num not in range(0,len(student_list)):
num = input(' , :')
num = int(num)
# 5.
student = student_list[num]
new_name = input(' (%s):'%student[0])
new_age = input(' (%s):'%student[1])
new_sex = input(' (%s):'%student[2])
new_phone = input(' (%s):'%student[3])
# 6.
student[0] = new_name
student[1] = new_age
student[2] = new_sex
student[3] = new_phone
print (' ')
#
# 1. 2. 3.
def delete_student():
# , ,
if len(student_list) == 0:
print (' , !')
#
return
print ('1. ')
print ('2. ')
#
num = input(' :')
#
num = int(num)
while num not in range(1, 3):
num = input(' , :')
num = int(num)
if num == 1:
# 1.
query_student()
index = input(' :')
index = int(index)
# 4.
while index not in range(0, len(student_list)):
index = input(' , :')
index = int(index)
#
del student_list[index]
# student_list.pop(index)
else:
#
rs = input(' ?y( )/n( ):')
if rs == 'y':
#
student_list.clear()
else:
print (' !')
def save_data():
# 1.
file_handle = open('studentv2.txt', mode='w')
# 2.
for student in student_list:
# for ,
# join() ,
s = ' '.join(student)
#
file_handle.write(s)
file_handle.write('
')
file_handle.close()
#
# os
import os
def read_date():
rs = os.path.exists('studentv2.txt')
if rs == True:
file_handle = open('studentv2.txt', mode='r')
contents = file_handle.readlines()
for msg in contents:
msg = msg.strip('
')
student = msg.split(' ')
student_list.append(student)
# ,
student_list = []
read_date()
while True:
print ('****** v2.0******')
print ('****** :Mr.Lei ******')
print ('* * 1. * *')
print ('* * 2. * *')
print ('* * 3. * *')
print ('* * 4. * *')
print ('* * 0. * *')
print ('***************************')
print ('***************************')
#
num = input(' :')
#
num = int(num)
# 0~5( 5),
while num not in range(0, 5):
num = input(' , :')
num = int(num)
# 2.
if num == 1:
add_student()
while True:
rs = input(' ?y( )/ n( ):')
if rs == 'y':
#
add_student()
else:
print (' !')
break
save_data()
#
elif num == 2:
update_student()
save_data()
#
elif num == 3:
query_student()
#
elif num == 4:
delete_student()
save_data()
#
else:
break