Advertisement
MRtecno98

Project Juno Source code V.1.3.2

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