def add_app():
apps = {}
print('{:*^53}'.format('添加你手机安装的APP'))
app_name = input('请输入App的名字:')
mb_used = input('请输入App的占用空间(单位:MB):')
app_setup_date = input('请输入APP的安装日期:')
apps['app_name'] = app_name
apps['mb_used'] = mb_used
apps['app_setup_date'] = app_setup_date
data.append(apps)
def query_app():
print('{:*^58}'.format('查询App'))
print('1.查询所有已安装的App')
print('2.输入App名查询')
print('选择操作:',end='')
while True:
try:
ask = int(input())
if ask != 1 and ask != 2:
raise ValueError
break
except:
print('您选择的选项不存在,请重选:',end='')
if ask == 1:
for i in data:
print('序号:{:^4}APP名字:{:^5}APP安装日期:{:^10}'.format(i['app_name'],i['mb_used'],i['app_setup_date']))
return True
if ask == 2:
print('请输入你安装的App名字:',end='')
while True:
app_name = input('')
for i in data:
if app_name not in i.values():
continue
break
else:
print('你未安装此款App,请重输:',end='')
continue
print('序号:{:^4} APP名字:{:^5} APP安装日期:{:^10}'.format(i['app_name'],i['mb_used'],i['app_setup_date']))
break
def main():
while True:
print('{:*^55}'.format('APP安装管理系统'))
print('{:*^55}'.format('1.添加已安装的App'))
print('{:*^55}'.format('2.查询己安装的App'))
print('请选择你的操作:', end='')
while True:
try:
ask_user = int(input())
if ask_user != 1 and ask_user != 2:
raise ValueError
break
except:
print('您选择的选项不存在,请重选:', end='')
if ask_user == 1:
add_app()
continue
if ask_user == 2:
query_app()
continue
if __name__ == '__main__':
data = []
main()