0

I'm trying to use an integer along with a letter to set a predefined variable to a number. I'm not quite sure how to explain this, so please see the code below...

from random import *
for i in range(0,playerDifficulty,1):
    tempRandomLine = randint(1, 10)
    l(tempRandomLine) = 15

Where I have the l(tempRandomLine), I need that to be able to set a variable predefined, such as l5, to 15, and I'm not quite sure how to do this. Any ideas? I am using Python 3

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
Starspiker
  • 11
  • 2

3 Answers3

2

You can use a list:

from random import *
l = [0] * 10
for i in range(0,playerDifficulty,1):
    tempRandomLine = randint(1, 10)
    l[tempRandomLine - 1] = 15
internet_user
  • 3,149
  • 1
  • 20
  • 29
0

I would separate create a separate variable for random numbers, concatenate that with the string, and then pass that as the parameter for your argument.

-1

try this out:

from random import *
playerDifficulty = 30

count = 0
listone = []
for i in range(0,playerDifficulty,1):
    count +=1
    if count <=15:
        tempRandomLine = randint(1, 10)
        l = 'l'+str(tempRandomLine) + str(count)
        listone.append(l)
    else:
        pass
print(listone)
ChameleonX
  • 87
  • 1
  • 10