-2

是否有一个函数,例如每次调用关键字或操作时,它会触发返回或计数以更改为一个值,您可以根据您说“喝一杯”的次数分配输出含义,输出将更改直到- 在下面的情况下 - 它的“都是空的:

if action = "喝一杯"

add 1 to count.drink

count 0 = print("full")

count 1 = print ("3/4 left")

count 2 = print("1/2 left")

count 3 = print ("1/4 left")

count 4 = print("all empty")

行动:喝一杯

count = 1

reaction "3/4 left"

行动:喝一杯

count = 2

reaction "1/2 left"

行动:喝一杯

count = 3   

reaction "1/4 left"

行动:喝一杯

count = 4

reaction "all empty"
4

1 回答 1

0

按照我的评论,我会提出一个解决方案。

actDictCount = {"take a drink":0}

actDictList = {"take a drink":["action1","action2","action3"]}

action = "take a drink"

actDictCount[action] +=1

print(actDictList[action][actDictCount[action]])
于 2013-10-09T07:00:02.437 回答