python小さな練習-小さな図書管理システム
4412 ワード
このコードで使用する必要があるのはすべてpythonの基礎的な知識です:循環、変数、判断、関数、break、辞書、リスト、文字列
コードは2つの部分に分かれています.
book_main.py:メインプログラム、システムの起動を担当
book_tools.py:ツールプログラム、システム内の各機能の実現を担当する
book_main.py
book_tools.py
これでいい
コードは2つの部分に分かれています.
book_main.py:メインプログラム、システムの起動を担当
book_tools.py:ツールプログラム、システム内の各機能の実現を担当する
book_main.py
"""
:
,
1、
2、
3、
0、
"""
from book_tools import *
while True:
# TODO
show_menu()
action = input(' :')
print(' 【%s】' % action)
if action in ['1', '2', '3']:
if action == '1':
#
add_book()
elif action == '2':
#
show_book()
else:
#
search_book()
elif action == '0':
print(' , ~~~')
break
else:
print(' , ')
book_tools.py
#
book_list = list()
def show_menu():
""" """
print("*" * 20)
print(' ~~~
')
print("""1、
2、
3、
0、 """)
print("*" * 20)
return
def add_book():
""" """
print('=' * 20)
print(' ')
# 1、
name = input(' :')
pub_date = input(' :')
comment = input(' :')
# 2、
book_dict = {"name": name,
"pub_date": pub_date,
"comment": comment
}
# 3、
book_list.append(book_dict)
print(book_list)
# 4、
print(' %s ' % name)
def show_book():
""" """
print('=' * 20)
print(' ')
#
if len(book_list) > 0:
#
for name in [' ', ' ', ' ']:
print(name, end='\t\t')
print()
#
print('-' * 40)
for book in book_list:
for value in book.values():
# ,
print(value, end='\t\t\t')
print()
else:
print(' , ')
def search_book():
""" """
print('=' * 20)
print(' ')
# 1、
book_name = input(' :')
# 2、 , , ,
# list ,
if len(book_list) > 0:
for book in book_list:
if book_name == book['name']:
#
for name in [' ', ' ', ' ']:
print(name, end='\t\t')
print()
#
print('-' * 40)
for value in book.values():
# ,
print(value, end='\t\t\t')
print()
# TODO
application(book)
break
else:
print(' %s ' % book_name)
else:
print(' %s ' % book_name)
def application(book_info):
"""
:param book_info: ,
"""
action = input(' '
'1: \t2: \t0: ')
if action == '1':
book_info['name'] = input_book_info(book_info['name'], ' :')
book_info['pub_date'] = input_book_info(book_info['pub_date'], ' :')
book_info['comment'] = input_book_info(book_info['comment'], ' :')
elif action == '2':
book_list.remove(book_info)
print(' %s' % book_info['name'])
def input_book_info(book_value, tip_message):
"""
:param book_value: ,
:param tip_message:
:return:
"""
# 1、
value = input(tip_message)
# 2、 , ,
if len(value) > 0:
return value
else:
return book_value
# 3、 ,
これでいい