Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: cp1252 -*-
- ##
- ## Copyright 2012 Félix Brezo (febrezo @ www.felixbrezo.com)
- ##
- ## This program is free software: you can redistribute it and/or modify
- ## it under the terms of the GNU General Public License as published by
- ## the Free Software Foundation, either version 3 of the License, or
- ## (at your option) any later version.
- ##
- ## Sira is distributed in the hope that it will be useful,
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ## GNU General Public License for more details.
- ##
- ## You should have received a copy of the GNU General Public License
- ## along with pySorteo. If not, see <http://www.gnu.org/licenses/>.
- import argparse
- from math import sqrt
- print "Parseando argumentos..."
- parser = argparse.ArgumentParser(description='Cálculo de las posibilidades de ganar en un sorteo de extracción de una bola en el que los agraciados serán el afortunado y los N-1 números siguientes.')
- parser.add_argument('boletos', metavar='N', type=int, nargs='+',
- help='lista de los números del sorteo')
- parser.add_argument('-e', '--entradas', metavar='NUM_ENTRADAS', required=True, help='el número de entradas que se sortean')
- parser.add_argument('-p', '--peticiones', metavar='NUM_PETICIONES', required=True, help='el número de peticiones enviadas al club')
- args = parser.parse_args()
- print "Arrancando procedimientos..."
- # Diccionario que almacenará el número de veces que ha salido cada opción.
- reparto={}
- if int(args.peticiones) < int(args.entradas):
- print "Enhorabuena, hay entradas para todos."
- # No hacemos nada más. ¿Qué queríais calcular?
- else:
- valido = True
- # Chequear que no hay ningún boleto superior al número de peticiones
- for k in args.boletos:
- if int(k)>int(args.peticiones):
- valido=False
- print "Se ha producido un error. El número de boleto "+str(k)+" es mayor que el número de peticiones ("+args.peticiones+")."
- break
- if valido:
- #recorremos todas las opciones
- for i in range(int(args.peticiones)):
- entradas=0
- for j in args.boletos:
- if ((i)+int(args.entradas)) < int(args.peticiones):
- if int(j-1)>=i and int(j-1) <(i+int(args.entradas)):
- entradas+=1
- else:
- # Volvemos al principio...
- if int(j-1)>=i:
- entradas+=1
- elif int(j-1) < ((i+int(args.entradas)) % int(args.peticiones)):
- entradas+=1
- if entradas in reparto:
- reparto[entradas]+=1
- else:
- reparto[entradas]=1
- # Mostramos la infor
- print "INFORMACIÓN"
- print "-----------"
- # Esto es culturilla... Gracias Wikipedia.
- print "\t- Media: la media (aritmética) es la cantidad total de la variable distribuida a partes iguales entre cada observación."
- print "\t- Varianza: la varianza representa la media aritmética de las desviaciones con respecto a la media que son elevadas al cuadrado."
- print "\t- Desviación típica: la desviación típica es una medida (cuadrática) que informa de la media de distancias que tienen los datos respecto de su media aritmética, expresada en las mismas unidades que la variable."
- print "\n"
- print "Calculando estadísticos..."
- print "\n"
- suma=0
- for i in reparto:
- suma+=float(i)*reparto[i]
- media = suma/float(args.peticiones)
- print "\tMedia:\t\t"+str(round(media,3))+" entradas."
- suma=0
- for i in reparto:
- suma+=float(i)**2*reparto[i]
- varianza= suma/float(args.peticiones)-media**2
- print "\tVarianza:\t"+str(round(varianza,3))
- print "\tDesv. T.:\t"+str(round(sqrt(varianza),3))+" entradas."
- print "\n"
- print "ASIGNACIÓN ESTIMADA (%)"
- print "-----------------------"
- for i in reparto:
- print "\tHay un "+ str(round(reparto[i]/float(args.peticiones)*100,3))+"% de posibilidades de llevarse justo "+str(i)+" entrada(s)."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement