Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you append a value to a variable name?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading