How to write the values ​​calculated in the script file excell ?

 __author__ = 'N1ZZE' #!/usr/bin/env python # -*- coding: utf-8 -*- import math import random TL = [0,0,0,0] TL1 = [0,0,0,0] Y = [] T = [] M = [] L = 1 Sumt = 0 t = 0 C = 1 N = 0 Nrab = int(input('Please Input Nrab: ')) Tkc = float(input('Please Input Tkc: ')) a = float(input('Please Input a: ')) count = 0 while (count < 10): y = random.random() Y.insert(count,y) if (count<5): x = 1/y x1 = math.log(x) x = x1/a T.append(x) else: x = 1/Y[count] x1 = L * math.log(x) M.append(x1) count +=1 while (N < Nrab): t = T[0] k = 0 if( t < TL[0] - Tkc): t = TL[0] + M[k]/C else: t = t + Tkc + M[k]/C TL1[0] = t if ((t < T[1]) and (t < T[2])): k = 0 elif ( T[1] < T[2] ): k = 1 t = T[1] else: k = 2 t = T[2] if ( t < TL[1] - Tkc): t = TL[1] + M[k]/C else: t = t + Tkc + M[k]/C TL1[1] = t if (t > T[4]): k = 4 t = T[4] if ( k==2 ): y1=random.random() y2=random.random() T[k]=T[k]+ math.log(1/y1)/a M[k]=L * math.log(1/y2) TL[1] = TL1[1] continue elif ( t < TL[2] - Tkc ): t = TL[2] + M[k]/C else: t = t + Tkc + M[k]/C TL1[2] = t if ( t > T[3] ): k = 3 t = T[3] if ( k == 1 ): y1=random.random() y2=random.random() T[k]=T[k]+ math.log(1/y1)/a M[k]=L * math.log(1/y2) TL[1] = TL1[1] TL[2] = TL1[2] continue elif ( t< TL[3] - Tkc): t = TL[3] + M[k]/C else: t = t + Tkc + M[k]/C TL1[3] = t if ( k == 0): Sumt = Sumt + t - T[0] N = N + 1 y1=random.random() y2=random.random() T[k]=T[k]+ math.log(1/y1)/a M[k]=L * math.log(1/y2) if ( k < 1 ): TL[0] = TL1[0] TL[1] = TL1[1] TL[2] = TL1[2] TL[3] = TL1[3] elif ( k == 3): TL[3] = TL1[3] elif ( k == 4): TL[2] = TL1[2] TL[3] = TL1[3] continue Zkc=Sumt/N print(Zkc) 

    3 answers 3

    Hmm, why not use the wonderful xlwt package?

    • I will try to use it) thanks) - Nizze
    • I will say from my experience: a very worthy thing. - skegg
    • It's hard for me, I'm a novice programmer. I will try to deal with it - Nizze
    • Yes there everything is elementary. - skegg
    • Great liba! Thanks for the info :) - AseN

    depending, what, Excel, if xlsx - then just xml-ku generate, business

    By the way, why was it necessary to upload all of my most beautiful code here? it would be better to put out failed export attempts, maybe it would be easier to help you

    PS If there is no need for anything other than what is laid out, then in Excel / Librekalka, all this can be done much simpler and more elegant.

    • It is necessary in xls. I did another 1 while in which the calculation was performed, and wrote down Zkc. But in fact, it turned out 24 equal values ​​((Sori for g *** okod. I am writing recently ( - Nizze

    csv , not?

    PS Extended author code:

     #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import division __author__ = 'N1ZZE' import math import random Nrab = int(input('Please Input Nrab: ')) Tkc = float(input('Please Input Tkc: ')) a = float(input('Please Input a: ')) def func(): TL = [0,0,0,0] TL1 = [0,0,0,0] Y = [] T = [] M = [] L = 1 Sumt = 0 t = 0 C = 1 N = 0 count = 0 while count < 10: y = random.random() Y.insert(count, y) if count < 5: x = 1 / y x1 = math.log(x) x = x1 / a T.append(x) else: x = 1 / Y[count] x1 = L * math.log(x) M.append(x1) count += 1 while N < Nrab: t = T[0] k = 0 if t < TL[0] - Tkc: t = TL[0] + M[k] / C else: t = t + Tkc + M[k] / C TL1[0] = t if t < T[1] and t < T[2]: k = 0 elif T[1] < T[2]: k = 1 t = T[1] else: k = 2 t = T[2] if t < TL[1] - Tkc: t = TL[1] + M[k] / C else: t = t + Tkc + M[k] / C TL1[1] = t if t > T[4]: k = 4 t = T[4] if k == 2: y1=random.random() y2=random.random() T[k]=T[k]+ math.log(1 / y1) / a M[k]=L * math.log(1 / y2) TL[1] = TL1[1] continue elif t < TL[2] - Tkc: t = TL[2] + M[k] / C else: t = t + Tkc + M[k] / C TL1[2] = t if t > T[3]: k = 3 t = T[3] if k == 1: y1=random.random() y2=random.random() T[k]=T[k]+ math.log(1 / y1) / a M[k]=L * math.log(1 / y2) TL[1] = TL1[1] TL[2] = TL1[2] continue elif t < TL[3] - Tkc: t = TL[3] + M[k] / C else: t = t + Tkc + M[k] / C TL1[3] = t if k == 0: Sumt = Sumt + t - T[0] N = N + 1 y1=random.random() y2=random.random() T[k]=T[k]+ math.log(1 / y1) / a M[k]=L * math.log(1 / y2) if k < 1: TL[0] = TL1[0] TL[1] = TL1[1] TL[2] = TL1[2] TL[3] = TL1[3] elif k == 3: TL[3] = TL1[3] elif k == 4: TL[2] = TL1[2] TL[3] = TL1[3] continue return Sumt, N with open('workfile.csv', 'w') as f: for i in range(24): Sumt, N = func() Zkc = str(Sumt / N) print(Zkc) f.write("{}\n".format(Zkc)) 
    • @Stan, Try to write more detailed answers. Explain what your statement is based on. - Deleted
    • Nizze wrote: Needed in xls. In order to write to xls, additional libraries are needed (which are not in Python in the base installation). I suggest using the csv format - this is a plain text file, writing it will not be a problem, in Excel it will open by default! - Stan
    • Well, if the document does not need a breakdown into sheets, etc. - csv would be a good (and non-hemorrhoidal) option. You can form it completely by hand, as in the code from Stan; You can work with the csv module, which seems to be immediately in the Python distribution. - Ekkertan