ti posto il mio codice:
codice:# calendario # importo la funzione random per generare "estrarre" casualmente #le squadre dall'urna(la lista squadre) from random import random #importo la funzione sleep per lasciare l'output di stato del programma # sullo schermo per alcuni secondi dopo la fine del programma from time import sleep #creo o apro in lettura il file campionato.html che ospitera' #i risultati dell'elaborazione file = open("campionato.html","w") # codice del programma sq = input("Quante squadre devono partecipare?") squadre = [] #controllo il numero delle squadre, se necessario aggiungo il turno di riposo if sq%2 != 0: squadre.append("riposo") #chiedo il nome di ciascuna squadra for k in range (1,sq+1): ask = "nome squadra %s" %(k) name = raw_input(ask) squadre.append(name) #creazione delle variabili che saranno poi utilizzate squadreBAK = [] squadreBAK = squadre[:] partite = [] partiteALL = [] tent = 0 sq = len(squadre) giornate = len(squadre)-1 CAMPIO = len(squadre)*(len(squadre)-1) PG = (len(squadre)+1)/2 #parte l'estazione print "ATTENDERE GENERAZIONE CALENDARIO IN CORSO" #finche' il numero delle partite non e' uguale a quello finale #creo le singole giornate while len(partiteALL) != CAMPIO: z = len(squadre) squadre = squadreBAK[:] partite = [] while squadre: h = int(z*random()) a = squadre.pop(h) z = len(squadre) k = int(z*random()) b = squadre.pop(k) z = len(squadre) VS = "%s - %s" % (a,b) if VS in partiteALL: squadre = squadreBAK[:] z = len(squadre) partite = [] tent = tent+1 # tent evita che le ultime giornate siano incompatibili # qualche suggerimento per la sua lunghezza nella funzione if successiva? if tent == (10000*sq): #se i tentativi effettuati sono troppi reinserisco la prima giornata for k in range(0,sq): a = partiteALL.pop(0) b = partiteALL.pop(0) else: partite.append(VS) VSR = "%s - %s" % (b,a) partite.append(VSR) partiteALL = partiteALL+partite PERC = 100*len(partiteALL)/CAMPIO PERC = str(PERC)+"%" print "completato %s" % (PERC) #inserisco le giornate nel file HTML(con il relativo formato) for k in range(1,(giornate+1)): GIOR = "Giornata %s"% (k) #print GIOR GIOR = ""+str(GIOR)+""+" " file.write(str(GIOR)) for k in range(0,PG): j = partiteALL.pop(0) w = partiteALL.pop(0) #print j j = str(j)+" " file.write(str(j)) file.close() #lascio l'output per 3 secondi(utile se si esegue il programma in modalita' DOS #(non lascia scappare la finestra appena ha eseguito le operazioni) sleep(3)


Rispondi quotando