-1

I am working on a problem where i should collect data from running program numerous times. For example, every time the program finishes commands, it give certain value t, which is different every time run it. My task is to collect t from N runs of the program. t is going to be different every run. here is the program:

import random 
th=0  
t=0
tr=0 
result=[]
for i in range(7):
  i=random.randint(0,1)
  result.append(i)
print(result)
a=0
b=len(result)-1
while th<50: 

  j=random.randint(a,b)
  i=j-1
  k=j+1
if k<b
   k=0
if result[i]==result[k]:
    if result[j]!=result[i]:
        result[j]==result[i]
         th=0
        t+=1
   else:
        th+=1 
        t+=1
   else:
    th+=1
    t+=1

   tr= t-th
print(tr)
print (result)

In this program every run gives you new result. In this generated array there will be obviously every time different arrangement of 0 and 1 and therefore, different t. So resulting t, tr, will be ofcourse different. I don't know wheter i should do it in new window, or there is a certain function that can do this. Also, if this question is to easy, and there is literature for it, please write what is the name of this kind of problem. thanks :)

btw, im working in python 3.6

Jelena Cvijan
  • 35
  • 1
  • 5
  • The problem with this question is not that it's too easy; it's too broad. There are many possible answers. Why would you run a program many times? Wouldn't it provide the same answer each time? – Bill Bell Nov 15 '17 at 16:36
  • Okay, thanks for this question, i will update my description. – Jelena Cvijan Nov 15 '17 at 16:37
  • Easiest and probably best would be for you to read how to turn this script into a Python function that can be executed repeatedly. Then, in the calling program, you would simply run the function as many times as necessary to achieve the variance goal you have set for yourself. You could also look into making the function return its results to the calling program, which would assume responsibility for writing them to a file for safekeeping. This is very basic programming, not difficult. – Bill Bell Nov 15 '17 at 16:58
  • Thank you, i managed to finish it. – Jelena Cvijan Nov 17 '17 at 13:49

1 Answers1

0

See how to make one Python script launch another: you can write a Python script to run the other script and gather the output. You can receive the output as return value from a function call, and tally it just as you would from any function.

Note that your "running program" and your master script need to agree on the form of the information returned: know the data types you're receiving. If you're in doubt, start by having your master script print out what it receives, and the type of each returned value.

Prune
  • 76,765
  • 14
  • 60
  • 81