Advertisement
MRtecno98

Project Juno Source code V.1.3.1

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