Advertisement
MarcoMala

EsercizioPythonTombolaMarco.py

Nov 23rd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #!/bin/env python3
  2. # Generatore Marco Malavolti - Esercizio Tombola Python3
  3.  
  4. import random
  5.  
  6. def estraiNumeri():
  7.     # genero la lista dei numeri da estrarre della tombola
  8.     listTombola = list(map(str, range(1, 91)))
  9.  
  10.     # genero la lista dei numeri estratti
  11.     listEstratti = list()
  12.  
  13.     while input("Vuoi caricare l'ultima partita? (S/N): ") in ['S','s']:
  14.  
  15.         f1 = open("/tmp/tombola.txt", "r")
  16.         f2 = open("/tmp/estratti.txt", "r")
  17.  
  18.         listTombolaOld = f1.readlines()[0]
  19.         listEstrattiOld = f2.readlines()[0]
  20.  
  21.         listTombola = listTombolaOld.split(",")
  22.         listEstratti = listEstrattiOld.split(",")
  23.  
  24.         f1.close()
  25.         f2.close()
  26.  
  27.         break
  28.  
  29.     while input("Premi 'Enter' per estrarre numero.(X per uscire): ") not in ['X','x']:
  30.         elementoEstratto = listTombola.pop(random.randint(0, len(listTombola)))
  31.         listEstratti.append(str(elementoEstratto))
  32.         print(listEstratti)
  33.  
  34.     f2 = open("/tmp/tombola.txt", "w")
  35.     f3 = open("/tmp/estratti.txt", "w")
  36.     f2.writelines(",".join(listTombola))
  37.     f3.writelines(",".join(listEstratti))
  38.     f2.close()
  39.     f3.close()
  40.  
  41.     return listTombola,listEstratti
  42.  
  43.  
  44. # MAIN
  45.  
  46. listTomb,listEstr = estraiNumeri()
  47.  
  48. print("\nELEMENTI ANCORA PRESENTI:\n")
  49. print(listTomb)
  50.  
  51. print("\nELEMENTI ESTRATTI:\n")
  52. print(listEstr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement