Advertisement
MRtecno98

Project Juno Source Code V.1.3.4

Jan 18th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.68 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. x["sai chi sono io?"] = "Tu sei " + UName
  109. Space(100)
  110.  
  111. print("Ciao, sono " + name + ", cosa mi vuoi dire?") #Messaggio di benvenuto
  112. #speak("Ciao, sono " + name + ", cosa mi vuoi dire?")
  113.  
  114. if int(time.strftime("%Y")) == CurrentYear + 1 :
  115.     print("Buon " + time.strftime("%Y") + "!!!!")
  116.     CurrentYear = CurrentYear + 1
  117.  
  118. #While infinito per ciclare
  119. while True :
  120.     d = input(">>> ") #Faccio la domanda
  121.  
  122.     dc = d.lower()
  123.     dc = dc.replace("!","")
  124.     dc = dc.replace("?","")
  125.     dc = dc.replace(",","")
  126.     dc = dc.replace(".","")
  127.  
  128.     d = dc
  129.    
  130.     if d.lower() == "esci" :
  131.         input("Ciao, spero di rivederti!")
  132.         break
  133.  
  134.     if "giochiamo a sasso carta forbice" in d.lower() or "vuoi giocare a sasso carta forbice" in d.lower():
  135.         input("\nOk, ti batterò di sicuro ;)\n")
  136.         SCF()
  137.         print("\nBella giocata eh?")
  138.         continue
  139.  
  140. #   if "resoconto delle partite a sasso carta forbice" in d.lower() :
  141. #      ResSCF()
  142. #      continue
  143.    
  144.     if "quanto fa" in d.lower() and "*" in d.lower() :
  145.         d = d.replace(" " , "")
  146.         num1 = int(d[8])
  147.         num2 = int(d[10])
  148.         risu = num1 * num2
  149.         print(num1 , "*" , num2 , "fa" , risu)
  150.         continue
  151.    
  152.     if "che ora è" in d.lower():
  153.         print("In questo momento l'ora esatta è:")
  154.         print(time.strftime("%c"))
  155.         continue
  156.    
  157.     if "quanto fa" in d.lower() and "+" in d.lower() :
  158.         d = d.replace(" " , "")
  159.         num1 = int(d[8])
  160.         num2 = int(d[10])
  161.         risu = num1 + num2
  162.         print(num1 , "+" , num2 , "fa" , risu)
  163.         continue
  164.    
  165.     if "quanto fa" in d.lower() and "-" in d.lower() :
  166.         d = d.replace(" " , "")
  167.         num1 = int(d[8])
  168.         num2 = int(d[10])
  169.         risu = num1 - num2
  170.         print(num1 , "-" , num2 , "fa" , risu)
  171.         continue
  172.    
  173.     if "quanto fa" in d.lower() and "/" in d.lower() :
  174.         d = d.replace(" " , "")
  175.         num1 = int(d[8])
  176.         num2 = int(d[10])
  177.         risu = num1 / num2
  178.         print(num1 , "/" , num2 , "fa" , risu)
  179.         continue
  180.    
  181.     if "pulisci" in d.lower() :
  182.         Space(100)
  183.         continue
  184.  
  185.     if "" == d.lower() :
  186.         continue
  187.    
  188.     if d.lower() in x :   #Controllo se è stata già fatta e registrata
  189.         print(x[d.lower()]) #Se sì stampo la risposta
  190.     else :  #Se no
  191.         print("Non ho capito, cosa devo rispondere?")
  192.         a = input(">>> ") #Chiedo all'utente cosa rispondere
  193.         if a.lower() != "niente" :
  194.             x[d.lower()] = a #E lo memorizzo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement