我正在用python编写一个程序来将游戏从特征形式转换为正常形式。我已经阅读了一些类似问题的答案:大多数人说最好使用字典。但是我认为如果您想为键指定特定名称,问题仍然存在。
假设我想为三个玩家的游戏构建一个程序,这很容易:
v1 = int(raw_input("How much is worth the coalition v(1)?"))
v2 = int(raw_input("How much is worth the coalition v(2)?"))
v3 = int(raw_input("How much is worth the coalition v(3)?"))
v12 = int(raw_input("How much is worth the coalition v(1,2)?"))
v13 = int(raw_input("How much is worth the coalition v(1,3)?"))
v23 = int(raw_input("How much is worth the coalition v(2,3)?"))
v123 = int(raw_input("How much is worth the coalition v(1,2,3)?"))
# and then I continue with the program
但是,如果我想为 n 个玩家的游戏构建一个程序……当然,我可以构建一个字典,但我仍然不知道如何按照我想要的方式调用每个键(v1、v2、v3,. .. ...,v123..n)。有任何想法吗?