dimanche 21 août 2016

Inputing 2 values through sys.argv: 1st to determin loop run for coin toss, second to determine the probability for binomial distribution

if len(sys.argv) < 3:
    sys.stdout.write ("2\nNo of Toss\t10\nSystem Probability\t0.8\n")
    sys.exit(0)
in_parameters = map (float, sys.argv[1:-2])
in_rownumber = int(sys.argv[-2])
out_filename = sys.argv[-1]
tmp_filename = out_filename + "_"
tmp_file = open(tmp_filename, 'w+b')
tmp_csv = csv.writer (tmp_file, delimiter=',', quotechar='"')

NToss = int(in_parameters[0])
PSys  = int(in_parameters[1])

def Toss():
    Draw = np.random.binomial(1, PSys, 1) 
    tmp_csv.writerow([str(Toss)])    

tmp_csv.writerow(["Toss"])  

for t in range(1,Toss+1):
    Spin()

New to python. Need assistance, run code that requires two inputs: 1st to #determine number of times to run a loop to toss a coin. 2nd as the #probability to be used in the binomial random equation. Results need to be #passed to temp csv file for specified no of toss.




Aucun commentaire:

Enregistrer un commentaire