Attachment 'radici.py'

Download

   1 #! /usr/bin/env python
   2 # -*- coding: utf-8 -*-
   3 
   4 import sys
   5 import optparse
   6 import math
   7 import libtavole
   8 
   9 usage = "usage: %prog [options]"
  10 parser = optparse.OptionParser(usage=usage)
  11 
  12 (outfile,massimo,numpage)=libtavole.opt_parsing(parser,1000)
  13 
  14 num_righe=50
  15 
  16 num_tabelle=int(math.ceil(float(massimo)/(2*num_righe)))
  17 
  18 TABS=[]
  19 
  20 for t in range(0,num_tabelle-1):
  21     print t
  22     TAB=[]
  23     for r in range(0,num_righe):
  24         R_a=[]
  25         R_b=[]
  26         num_a=r+t*2*num_righe+1
  27         num_b=num_a+num_righe
  28         R_a=[str(num_a),str(num_a*num_a),str(num_a*num_a*num_a),
  29              "%.5f" % math.sqrt(num_a),
  30              "%.5f" % math.pow(num_a,1/3.0)]
  31         R_b=[str(num_b),str(num_b*num_b),str(num_b*num_b*num_b),
  32              "%.5f" % math.sqrt(num_b),
  33              "%.5f" % math.pow(num_b,1/3.0)]
  34         TAB.append(R_a+R_b)
  35     TABS.append(TAB)
  36 
  37 N=massimo-2*num_righe*len(TABS)
  38 old_num_righe=num_righe
  39 num_righe=int(math.ceil(N/2.0))
  40 
  41 t=(num_tabelle-1)
  42 print t
  43 TAB=[]
  44 for r in range(0,num_righe):
  45     R_a=[]
  46     R_b=[]
  47     num_a=1+r+t*2*old_num_righe
  48     num_b=num_a+num_righe
  49     R_a=[str(num_a),str(num_a*num_a),str(num_a*num_a*num_a),
  50          "%.5f" % math.sqrt(num_a),
  51          "%.5f" % math.pow(num_a,1/3.0)]
  52     if num_b<=massimo:
  53         R_b=[str(num_b),str(num_b*num_b),str(num_b*num_b*num_b),
  54              "%.5f" % math.sqrt(num_b),
  55              "%.5f" % math.pow(num_b,1/3.0)]
  56     else:
  57         R_b=["","","","",""]
  58     TAB.append(R_a+R_b)
  59 TABS.append(TAB)
  60 
  61 titolo="Radici e potenze fino a "+str(massimo)
  62 
  63 if outfile=="-":
  64     fd=sys.stdout
  65 else:
  66     fd=open(outfile,"w")
  67 
  68 libtavole.print_header(fd,titolo,numpage)
  69 
  70 h=">{\\bf}r*{4}{r}"
  71 
  72 colorflag=False
  73 
  74 def printrow(R):
  75     global colorflag
  76     if colorflag:
  77         fd.write("\\rowcolor{rcolorata}\n")
  78     fd.write("&".join(R)+"\\\\\n\n")
  79     colorflag=not colorflag
  80 
  81 prima=True
  82 for TAB in TABS:
  83     colorflag=False
  84     fd.write("\\mbox{ }\n\n")
  85     fd.write("\\vfill\n\n")
  86 
  87     fd.write("\\begin{tabular}{"+h+"@{\\hspace{8mm}}"+h+"}\n")
  88     fd.write("\\rowcolor{rtitolo}\n")
  89     fd.write(" & $n^2$ & $n^3$ & $\\sqrt{n}$ & $\\sqrt[3]{n}$ &")
  90     fd.write(" & $n^2$ & $n^3$ & $\\sqrt{n}$ & $\\sqrt[3]{n}$ \\\\\n")
  91     fd.write("\\hline\n")
  92     map(lambda R: printrow(R),TAB)
  93     fd.write("\\end{tabular}\n\n")
  94 
  95     if prima:
  96         prima=False
  97         fd.write("\\vspace{2mm}\n\n")
  98     else:
  99         fd.write("\\vfill\n\n")
 100 
 101     fd.write("\\mbox{ }\n\n")
 102     fd.write("\\newpage\n\n")
 103         
 104 
 105 libtavole.print_end(fd)
 106 
 107 
 108 if outfile!="-":
 109     fd.close()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.

Gianozia Orientale: BiblioTavoleNumeriche (last edited 2010-08-02 15:18:07 by chiara)