本帖最后由 Stubborn 于 2020-5-26 00:49 编辑 # -*- coding: utf-8 -*-
# !/usr/bin/python3
"""
@ version: ??
@ author: Alex
@ file: test
@datetime: 2020/5/25 - 22:38
@explain:
"""
import time
class AppDepot:
class App:
__slots__ = ["name", "mb_used", "app_setup_date"]
def __init__(self, name, size):
self.name = name
self.mb_used = size
self.app_setup_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
def __str__(self):
return f"app名字:{self.name},占用内存:{self.mb_used}MB, 安装时间{self.app_setup_date}"
def __init__(self, size=0x2000):
self.size = size
self.data = dict()
def add_app(self):
name = input("输入安装APP名字:")
while True:
try:
if self.data.get(name, None) is not None: raise NameError
size = int(input("输入安装APP内存大小:"))
if self.size - size < 0: raise TypeError
break
except ValueError:
print("输入正确的数字:")
except TypeError:
print(f"当前空前内存不足, 剩余{self.size}MB空间")
except NameError:
name = input("APP名字已经存在,请更换其他名字:")
self.data[name] = AppDepot.App(name, size)
self.size -= size
def query(self):
print("""
************查询App*************
1.查询所有己安装的App
2.输入App名查询
3.返回APP安装管理系统
""")
flag = "请选择你的操作:"
while True:
_ = input(flag)
if _ == "1":
self.query_app()
elif _ == "2":
name = input("请输入App的名字: ")
if self.query_app(flag=name):
print("你未安装此款App,请重输:")
elif _ == "3":
break
else:
flag = "操作失误,请重新选择"
def query_app(self, flag=None):
if flag is None:
for val in self.data.values():
print(val)
else:
data = self.data.get(flag, None)
if data is not None:
print(data)
else:
return True
print(F"当前总计安装{len(self.data)}个APP,消耗内存{0x2000 - self.size}MB, 剩余内存{self.size}MB")
def main():
a = """
***************APP安装管理系统*************
***************1.安装新的App***************
***************2.查询己安装的App***********
***************(Q,q) 退出系统 *************
"""
print(a)
apps = AppDepot()
flag = "请选择你的操作:"
while True:
_ = input(flag)
if _ == "1":
print("********添加你手机安装的APP*********")
apps.add_app()
flag = f"安装成功,当前剩余{apps.size}MB空间,请继续选择你的操作:"
elif _ == "2":
apps.query()
print(a)
flag = "请选择你的操作:"
elif _ == "Q" or _ =="q":
exit()
else:
flag = "您选择的选项不存在,请重选:"
main()
Stubbron敲码不易~如果有帮助到你,记得给#6的Twilight6最佳鼓励吧~ |