"""
#要求做一个系统菜单,输入数字进入对应菜单,包含以下内容,正常操作不能报错:
# 菜单1:列印所有产品价格和库存
# 菜单2:修改产品价格
# 菜单3:增加库存
# 菜单4:购买指定数量产品
# 菜单5:增加新产品 作为思考题
# 菜单0:退出当前系统
"""
price = {'vegetables': '3','eggs': '4','rice': '2'} # 价格dict
stock = {'vegetables': '0','eggs': '0','rice': '0'} # 库存dict
tip = '''
1:列印所有产品价格和库存
2:修改产品价格
3:增加库存
4:购买指定数量产品
5:增加新产品 作为思考题
0:退出当前系统
'''
def main():
while True:
global price, stock
a = input(f'Please enter a number:{tip}\n').strip()
if a == '0':
print('Exit!')
break
elif a == '1':
style = '{:15}{:6}{:5}'
print(style.format('Name', 'price', 'stock'))
for (n, p), (_, s) in zip(price.items(), stock.items()):
print(style.format(n, p, s))
print()
elif a == '2':
while True:
n = input('enter a product name to modify its price: ')
if n in price:
break
print('invalid input! Should be "{}".'.format(
'" or "'.join(price)))
p = input('enter a new price of this product: ')
price[n] = p
elif a == '3':
while True:
n = input('enter a product name to increase its stock: ')
if n in stock:
break
print('Invalid input! Should be "{}".'.format(
'" or "'.join(stock)))
while True:
s = input('enter a integer to update the stock of it: ')
try:
s = int(s)
break
except:
print('Invalid input, must be a integer!')
stock[n] = str(int(stock[n]) + s)
elif a == '4':
while True:
n = input('enter a product name to buy it: ')
if n in stock:
break
print('Invalid input! Should be "{}".'.format(
'" or "'.join(stock)))
while True:
s = input('enter a integer for how many to buy: ')
try:
s = int(s)
if s <=0 or s > int(stock[n]):
raise
break
except:
print('Invalid input, must be a positive integer and '
'less than{}!'.format(stock[n]))
y = input('You want to buy {} X {}, which cost {}? (y)/n '.format(
n, s, int(price[n]) * s))
if y.strip().lower() in ('y', ''):
stock[n] = str(int(stock[n]) - s)
print('You pay {} and get {} {}'.format(int(price[n]*s), s, n))
elif a == '5':
print('Uncomplete...\n')
if __name__ == '__main__':
main()
在下拉菜单里选择设备类型,根据类型来展示对应的设备名称。
监听类型下拉框的值,根据类型去设备表里查对应的设备名称。
后端返回list后再展示在下拉框里。
二级联动下拉框,选择了类型,就展示对应的名称可供选择
关闭对话框再打开,没选择类型,名称下拉框里直接返回了上次的结果
对话框里进行初始化
python入门教程如下:
准备材料:windows电脑、python
1、这里简单告用python软件编写的一个关于货物售价折扣方面的一个计算程序,首先打开python软件。
2、进入python后,会出现如图所示界面,按照图中箭头指示,先选择File选项,然后在下拉菜单中选择New file选项。
3、选择完毕后,会出现一个新的界面,如图箭头和红色框指示。
4、进入这个新的界面,在里面输入自己想编辑的程序,如图所示是编写的一个关于货物售价折扣方面的一个简单的计算程序。
5、程序输入完毕后,按照图中箭头和红色框指示,先选择Run选项,然后在下拉菜单中选择Run Module(注:除此方法外还可以点击键盘F5)。
6、此时会在原界面出现如图所示的字样,这是因为编写程序编辑好的,此时可以输入一个数字,然后回车,又会让输入一个折扣,输入完即可得出最后售价结果。
7、如图所示,这里输入的原价是10,折扣是0.2,故此系统根据编写的程序计算除了打折后的价格为2。