英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论