计数返回顺序输出的函数

时间:2013-10-09 06:49:18

标签: python printing count return output

是否存在类似于每次调用关键字或操作时的函数,它会触发返回或计数以更改为可以分配输出的值 意思是根据你说“喝一杯”多少次,输出会改变,直到 - 在下面的情况下 - 它“全是空的:

如果行动=“喝一杯”

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"

1 个答案:

答案 0 :(得分: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]])