Advertisement
MRtecno98

Project Juno Source code V.1.3.0

Jan 15th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.44 KB | None | 0 0
  1. import random
  2. import time
  3. from gtts import gTTS
  4. UName = ""
  5. z = 0
  6. i = 1
  7. i = i - 1
  8. name = "Juno" #Nome del'AI
  9. CurrentYear = 2017
  10. #Definisco un dizionario(o HashMap) per salvare domande e risposte
  11. x = {"Come ti chiami?" : "Mi chiamo " + name , "Quanti anni hai?" : "2 anni" , "Come stai?" : "Bene" , "Ciao " + name : "Ciao anche a te" , "Bravo "  + name : "Grazie!" , "Sai chi sono io?" : "Tu sei " + UName}
  12. #E un'array per salvare i punteggi SCF(Sasso Carta Forbice)
  13. pscf = {}
  14.  
  15. def ResSCF() :
  16.     print("Resoconto delle ultime partite a Sasso Carta Forbice:\n")
  17.     while i <= len(pscf) - 1 :
  18.         print(pscf[i])
  19.         i = i + 1
  20.  
  21. def speak(text) :
  22.     tts = gTTS(text = text, lang = "it")
  23.     tts.save("test.mp3")
  24.  
  25. def SCF() :
  26.     print("=========================================")
  27.     print("Sasso Carta Forbice remastered for Python")
  28.     print("      by NEGCommand & MRtecno98")
  29.     print("=========================================")
  30.     input("            Enter to start")
  31.  
  32.     print("\n\n\nInserire il numero di match(-1 per infinito)")
  33.     bo = 1
  34.     puntggutente = 0
  35.     puntggcomput = 0
  36.     while bo == 1:
  37.         try :
  38.             ms = int(input(">>> "))
  39.         except ValueError:
  40.             print("Inserisci un numero, non una lettera")
  41.         else:
  42.             bo = 0
  43.  
  44.     while ms != 0:
  45.         oggutente = input('\nInserisci un oggetto [Sasso|Carta|Forbice|Esci]: ')
  46.         oggcomp = random.randint(1, 3)
  47.    
  48.         if "E" in oggutente or oggutente == "Esci" :
  49.             break
  50.    
  51.         if oggutente == 'Sasso' or "s" in oggutente or "S" in oggutente or oggutente == "sasso":
  52.             if oggcomp == 1:
  53.                 print('[Tu:Sasso ','Pc:'+'Sasso]','  PAREGGIO')
  54.             elif oggcomp == 2:
  55.                 print('[Tu:Sasso ','Pc:'+'Carta]','  HAI PERSO')
  56.                 puntggcomput = puntggcomput + 1
  57.             elif oggcomp == 3:
  58.                 print('[Tu:Sasso ','Pc:'+'Forbice]','  HAI VINTO')
  59.                 puntggutente = puntggutente + 1
  60.             ms = ms - 1
  61.         elif oggutente == 'Carta' or "c" in oggutente or "C" in oggutente or oggutente == "carta":
  62.             if oggcomp == 1:
  63.                 print('[Tu:Carta ','Pc:'+'Sasso]','  HAI VINTO')
  64.                 puntggutente = puntggutente + 1
  65.             elif oggcomp == 2:
  66.                 print('[Tu:Carta ','Pc:'+'Carta]','  PAREGGIO')
  67.             elif oggcomp == 3:
  68.                 print('[Tu:Carta ','Pc:'+'Forbice]','  HAI PERSO')
  69.                 puntggcomput = puntggcomput + 1
  70.             ms = ms - 1
  71.         elif oggutente == 'Forbice' or "f" in oggutente or "F" in oggutente or oggutente == "forbice":
  72.             if oggcomp == 1:
  73.                 print('[Tu:Forbice ','Pc:'+'Sasso]','  HAI PERSO')
  74.                 puntggcomput = puntggcomput + 1
  75.             elif oggcomp == 2:
  76.                 print('[Tu:Forbice ','Pc:'+'Carta]','  HAI VINTO')
  77.                 puntggutente = puntggutente + 1
  78.             elif oggcomp == 3:
  79.                 print('[Tu:Forbice ','Pc:'+'Forbice]','  PAREGGIO')
  80.             ms = ms - 1
  81.         else:
  82.             print("Inserire un oggetto valido")
  83.  
  84.     if puntggutente > puntggcomput :
  85.         print("\nTOTALE: [Tu:" + str(puntggutente) + "  " + "Pc:" + str(puntggcomput) + "]" , "HAI VINTO!")
  86.         pscf[len(pscf)] = time.strftime("%c") + ":" , "[Tu:" + str(puntggutente) + "  " + "Pc:" + str(puntggcomput) + "]" , "VITTORIA"
  87.  
  88.     if puntggutente < puntggcomput :
  89.         print("\nTOTALE: [Tu:" + str(puntggutente) + "  " + "Pc:" + str(puntggcomput) + "]" , "HAI PERSO!")
  90.         pscf[len(pscf)] = time.strftime("%c") + ":" , "[Tu:" + str(puntggutente) + "  " + "Pc:" + str(puntggcomput) + "]" , "SCONFITTA"
  91.  
  92.     if puntggutente == puntggcomput :
  93.         print("\nTOTALE: [Tu:" + str(puntggutente) + "  " + "Pc:" + str(puntggcomput) + "]" , "PAREGGIO")
  94.         pscf[len(pscf)] = time.strftime("%c") + ":" , "[Tu:" + str(puntggutente) + "  " + "Pc:" + str(puntggcomput) + "]" , "PAREGGIO"
  95.  
  96.    
  97.  
  98. while z <= 100 :
  99.     print("\n")
  100.     z = z + 1
  101. z = 0
  102. UName = input("Qual'è il tuo nome? ")
  103.  
  104. while z <= 100 :
  105.     print("\n")
  106.     z = z + 1
  107. z = 0
  108. print("Ciao, sono " + name + ", cosa mi vuoi dire?") #Messaggio di benvenuto
  109. speak("Ciao, sono " + name + ", cosa mi vuoi dire?")
  110.  
  111. if int(time.strftime("%Y")) == CurrentYear + 1 :
  112.     print("Buon " + time.strftime("%Y") + "!!!!")
  113.     CurrentYear = CurrentYear + 1
  114.  
  115. #While infinito per ciclare
  116. while True :
  117.     d = input(">>> ") #Faccio la domanda
  118.    
  119.     if d.lower() == "esci" :
  120.         input("Ciao, spero di rivederti!")
  121.         break
  122.  
  123.     if "giochiamo a sasso carta forbice" in d.lower() or "vuoi giocare a sasso carta forbice" in d.lower():
  124.         input("\nOk, ti batterò di sicuro ;)\n")
  125.         SCF()
  126.         print("\nBella giocata eh?")
  127.         continue
  128.  
  129. #   if "resoconto delle partite a sasso carta forbice" in d.lower() :
  130. #      ResSCF()
  131. #      continue
  132.    
  133.     if "quanto fa" in d.lower() and "*" in d.lower() :
  134.         d = d.replace(" " , "")
  135.         num1 = int(d[8])
  136.         num2 = int(d[10])
  137.         risu = num1 * num2
  138.         print(num1 , "*" , num2 , "fa" , risu)
  139.         continue
  140.    
  141.     if "che ora è" in d.lower():
  142.         print("In questo momento l'ora esatta è:")
  143.         print(time.strftime("%c"))
  144.         continue
  145.    
  146.     if "quanto fa" in d.lower() and "+" in d.lower() :
  147.         d = d.replace(" " , "")
  148.         num1 = int(d[8])
  149.         num2 = int(d[10])
  150.         risu = num1 + num2
  151.         print(num1 , "+" , num2 , "fa" , risu)
  152.         continue
  153.    
  154.     if "quanto fa" in d.lower() and "-" in d.lower() :
  155.         d = d.replace(" " , "")
  156.         num1 = int(d[8])
  157.         num2 = int(d[10])
  158.         risu = num1 - num2
  159.         print(num1 , "-" , num2 , "fa" , risu)
  160.         continue
  161.    
  162.     if "quanto fa" in d.lower() and "/" in d.lower() :
  163.         d = d.replace(" " , "")
  164.         num1 = int(d[8])
  165.         num2 = int(d[10])
  166.         risu = num1 / num2
  167.         print(num1 , "/" , num2 , "fa" , risu)
  168.         continue
  169.    
  170.     if "pulisci" in d.lower() :
  171.         while z <= 100 :
  172.             print("\n")
  173.             z = z + 1
  174.         z = 0
  175.         continue
  176.    
  177.     if d.lower() in x :   #Controllo se è stata già fatta e registrata
  178.         print(x[d]) #Se sì stampo la risposta
  179.     else :  #Se no
  180.         print("Non ho capito, cosa devo rispondere?")
  181.         a = input(">>> ") #Chiedo all'utente cosa rispondere
  182.         if a.lower() != "niente" :
  183.             x[d.lower()] = a #E lo memorizzo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement