0

I created N to combine test1 and test2 making it 1 line 10 digits

How do I assign a variable that carries this whole function? So I could use
print A and it prints N 10 times. I need to use results in future for something else.
Outside of the code below N prints the whole thing just once. I don't want to use

print N
print N
print N
print N...


Here's the original code

for i in range(10):
    test1 = stats.rv_discrete(name='test1', values=(numbers, probability))
    test1_results = test1.rvs(size=8)
    test2 = stats.rv_discrete(name='test2', values=(numbers2, probability2))
    test2_results = test2.rvs(size=2)
    N =  str(test1_results) + str(test2_results)  
   print ''.join(str(v) for v in N)   
xandermonkey
  • 4,054
  • 2
  • 31
  • 53
Aset
  • 11
  • 4

1 Answers1

0

You'd be better off writing this as a function instead of storing the information in a variable.

def myFunction():
    for i in range(10):
        test1 = stats.rv_discrete(name='test1', values=(numbers, probability))
        test1_results = test1.rvs(size=8)
        test2 = stats.rv_discrete(name='test2', values=(numbers2, probability2))
        test2_results = test2.rvs(size=2) 
        N =  str(test1_results) + str(test2_results)  
    return ''.join(str(v) for v in N)

After defining this function you can say A = myFunction() and then write print A.

xandermonkey
  • 4,054
  • 2
  • 31
  • 53
  • ok now I'm running into other problem. It wont stop printing results until it gives me RuntimeError: maximum recursion depth exceeded I needed 10 results only – Aset Jul 13 '16 at 12:46
  • Please read up on what a function is. Also, read about what [recursion](http://stackoverflow.com/questions/717725/understanding-recursion) is. You're clearly writing a recursive call in the definition of your function without any base case to end the recursion at. This is not required to solve your problem. If you want more help, provide more detail into your code and what your problem is. – xandermonkey Jul 13 '16 at 13:34