Python 最新词典
这是我的剧本Python 最新词典,python,python-2.7,dictionary,Python,Python 2.7,Dictionary,这是我的剧本 shop = ["Apple" , "orange", "mangoo" , "Tomato" , "grape"] dict = {} #List Shop x = """ 1. apple 2. orange 3. mangoo 4. tomato 5. grape """ print x #Screen showing in monitor while True: buy = int(raw_input('what do u want to buy?" (use
shop = ["Apple" , "orange", "mangoo" , "Tomato" , "grape"]
dict = {}
#List Shop
x = """
1. apple
2. orange
3. mangoo
4. tomato
5. grape """
print x
#Screen showing in monitor
while True:
buy = int(raw_input('what do u want to buy?" (use number 1-7): '))
buy = shop[buy-1]
print "You want" , buy
equal = int(raw_input('how much? : '))
bb = {buy:equal}
dict.update(bb)
print dict, x
如果我选择相同的顺序。旧值将随最新值更改
我想让它,像这样
我选择“苹果”,我想买“3”
在下一个命令中,我想再次购买“苹果”
但我会买“6”。
所以苹果的平均值是“9”
注意:Python2.7,此方法不使用zip、def、return和break选项。注意:
dict
是字典的保留关键字。用我的字典之类的东西
试试这个:
my_dict[buy] = my_dict.get(buy, 0) + equal
dict.get的语法:
dict.get(key[,default])
代码:
注意:
dict
是字典的保留关键字。用我的字典之类的东西
试试这个:
my_dict[buy] = my_dict.get(buy, 0) + equal
dict.get的语法:
dict.get(key[,default])
代码:
@Helonder777我更新了整个代码,请看我的更新post@Helonder777我更新了全部代码,请参阅我更新的帖子