如何将一个值附加到变量名称?

huangapple go评论73阅读模式
英文:

How do you append a value to a variable name?

问题

I'm making a program that displays data from the Keno API (Keno is a gambling "site" where you need to pick numbers and match those numbers to the ones the game picks). This API gets this data and allows the user to input their picks and see if they won.

But now to my problem, In Keno you can pick a certain amount of numbers. For example you can pick 3 numbers, (this is referred to as spot 3, pick 5 numbers and that's spot 5 and so on.). And each of these spots have their own win list. Now my script has these spot win lists in tables that are named c_spotx_WinList where x is the spot.

In this simplified code snippet I have built a smaller version of what I'm trying to achieve:

number = 1
index = 4
Table1 = [0, 1, 2, 3, 4, 5]
Table2 = [0, 10, 20, 30, 40, 50]
while True:
    result = Table1[index] + number
    print(result)

On line 6 is where I want to add the value of number to be added to the end of Table1 to create Table1 from which I can use index to get the requested value.

Is this even possible?
Also if you want to see the original code it is viewable here: Main.py and WinList.py

英文:

Im making a program that displays data from the Keno API (Keno is a gambling "site" where you need to pick numbers and match those numbers to the ones the game picks). This API gets this data and allows the user to input their picks and see if they won.

But now to my problem, In Keno you can pick a certain amount of numbers. For example you can pick 3 numbers, (this is referred to as spot 3, pick 5 numbers and thats spot 5 and so on.). And each of these spots have their own win list. Now my script has these spot winlists in tables that are named c_spotx_WinList where x is the spot.

In this simplfied code snippet I have built a smaller version of what I'm trying to achieve

number = 1
index = 4
Table1 = [0, 1, 2, 3, 4, 5]
Table2 = [0, 10, 20, 30, 40, 50]
while True:
    result = Table + number[index]
    print(result)

On line 6 is where I want to add the value of number to be added to the end of Table to create Table1 from which I can use Index to get the requested value.

Is this even possible?
Also if you want to see the orginal code it is viewable here: Main.py and WinList.py

答案1

得分: 1

这是正确的做法:

number = 1
index = 4
Tables = [
 [0, 1, 2, 3, 4, 5],
 [0, 10, 20, 30, 40, 50]
]

result = Tables[number][index]
print(result)

输出:

40
英文:

Here is the right way to do this kind of thing.

number = 1
index = 4
Tables = [
 [0, 1, 2, 3, 4, 5],
 [0, 10, 20, 30, 40, 50]
]

result = Tables[number][index]
print(result)

Output:

40

huangapple
  • 本文由 发表于 2023年7月17日 09:02:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76700980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定