Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- from gtts import gTTS
- UName = ""
- z = 0
- i = 1
- i = i - 1
- name = "Juno" #Nome del'AI
- name = name.lower()
- CurrentYear = 2017
- #Definisco un dizionario(o HashMap) per salvare domande e risposte
- 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}
- #E un'array per salvare i punteggi SCF(Sasso Carta Forbice)
- pscf = {}
- def ResSCF() :
- print("Resoconto delle ultime partite a Sasso Carta Forbice:\n")
- while i <= len(pscf) - 1 :
- print(pscf[i])
- i = i + 1
- def Space(num) :
- z = 0
- while z <= num :
- print("\n")
- z = z + 1
- z = 0
- def speak(text) :
- tts = gTTS(text = text, lang = "it")
- tts.save("test.mp3")
- def SCF() :
- print("=========================================")
- print("Sasso Carta Forbice remastered for Python")
- print(" by NEGCommand & MRtecno98")
- print("=========================================")
- input(" Enter to start")
- print("\n\n\nInserire il numero di match(-1 per infinito)")
- bo = 1
- puntggutente = 0
- puntggcomput = 0
- while bo == 1:
- try :
- ms = int(input(">>> "))
- except ValueError:
- print("Inserisci un numero, non una lettera")
- else:
- bo = 0
- while ms != 0:
- oggutente = input('\nInserisci un oggetto [Sasso|Carta|Forbice|Esci]: ')
- oggcomp = random.randint(1, 3)
- if "e" in oggutente.lower() or oggutente.lower() == "esci" :
- break
- if oggutente == 'Sasso' or "s" in oggutente or "S" in oggutente or oggutente == "sasso":
- if oggcomp == 1:
- print('[Tu:Sasso ','Pc:'+'Sasso]',' PAREGGIO')
- elif oggcomp == 2:
- print('[Tu:Sasso ','Pc:'+'Carta]',' HAI PERSO')
- puntggcomput = puntggcomput + 1
- elif oggcomp == 3:
- print('[Tu:Sasso ','Pc:'+'Forbice]',' HAI VINTO')
- puntggutente = puntggutente + 1
- ms = ms - 1
- elif oggutente == 'Carta' or "c" in oggutente or "C" in oggutente or oggutente == "carta":
- if oggcomp == 1:
- print('[Tu:Carta ','Pc:'+'Sasso]',' HAI VINTO')
- puntggutente = puntggutente + 1
- elif oggcomp == 2:
- print('[Tu:Carta ','Pc:'+'Carta]',' PAREGGIO')
- elif oggcomp == 3:
- print('[Tu:Carta ','Pc:'+'Forbice]',' HAI PERSO')
- puntggcomput = puntggcomput + 1
- ms = ms - 1
- elif oggutente == 'Forbice' or "f" in oggutente or "F" in oggutente or oggutente == "forbice":
- if oggcomp == 1:
- print('[Tu:Forbice ','Pc:'+'Sasso]',' HAI PERSO')
- puntggcomput = puntggcomput + 1
- elif oggcomp == 2:
- print('[Tu:Forbice ','Pc:'+'Carta]',' HAI VINTO')
- puntggutente = puntggutente + 1
- elif oggcomp == 3:
- print('[Tu:Forbice ','Pc:'+'Forbice]',' PAREGGIO')
- ms = ms - 1
- else:
- print("Inserire un oggetto valido")
- if puntggutente > puntggcomput :
- print("\nTOTALE: [Tu:" + str(puntggutente) + " " + "Pc:" + str(puntggcomput) + "]" , "HAI VINTO!")
- pscf[len(pscf)] = time.strftime("%c") + ":" , "[Tu:" + str(puntggutente) + " " + "Pc:" + str(puntggcomput) + "]" , "VITTORIA"
- if puntggutente < puntggcomput :
- print("\nTOTALE: [Tu:" + str(puntggutente) + " " + "Pc:" + str(puntggcomput) + "]" , "HAI PERSO!")
- pscf[len(pscf)] = time.strftime("%c") + ":" , "[Tu:" + str(puntggutente) + " " + "Pc:" + str(puntggcomput) + "]" , "SCONFITTA"
- if puntggutente == puntggcomput :
- print("\nTOTALE: [Tu:" + str(puntggutente) + " " + "Pc:" + str(puntggcomput) + "]" , "PAREGGIO")
- pscf[len(pscf)] = time.strftime("%c") + ":" , "[Tu:" + str(puntggutente) + " " + "Pc:" + str(puntggcomput) + "]" , "PAREGGIO"
- Space(100)
- UName = input("Qual'è il tuo nome? ")
- x["sai chi sono io?"] = "Tu sei " + UName
- Space(100)
- print("Ciao, sono " + name + ", cosa mi vuoi dire?") #Messaggio di benvenuto
- speak("Ciao, sono " + name + ", cosa mi vuoi dire?")
- if int(time.strftime("%Y")) == CurrentYear + 1 :
- print("Buon " + time.strftime("%Y") + "!!!!")
- CurrentYear = CurrentYear + 1
- #While infinito per ciclare
- while True :
- d = input(">>> ") #Faccio la domanda
- if d.lower() == "esci" :
- input("Ciao, spero di rivederti!")
- break
- if "giochiamo a sasso carta forbice" in d.lower() or "vuoi giocare a sasso carta forbice" in d.lower():
- input("\nOk, ti batterò di sicuro ;)\n")
- SCF()
- print("\nBella giocata eh?")
- continue
- # if "resoconto delle partite a sasso carta forbice" in d.lower() :
- # ResSCF()
- # continue
- if "quanto fa" in d.lower() and "*" in d.lower() :
- d = d.replace(" " , "")
- num1 = int(d[8])
- num2 = int(d[10])
- risu = num1 * num2
- print(num1 , "*" , num2 , "fa" , risu)
- continue
- if "che ora è" in d.lower():
- print("In questo momento l'ora esatta è:")
- print(time.strftime("%c"))
- continue
- if "quanto fa" in d.lower() and "+" in d.lower() :
- d = d.replace(" " , "")
- num1 = int(d[8])
- num2 = int(d[10])
- risu = num1 + num2
- print(num1 , "+" , num2 , "fa" , risu)
- continue
- if "quanto fa" in d.lower() and "-" in d.lower() :
- d = d.replace(" " , "")
- num1 = int(d[8])
- num2 = int(d[10])
- risu = num1 - num2
- print(num1 , "-" , num2 , "fa" , risu)
- continue
- if "quanto fa" in d.lower() and "/" in d.lower() :
- d = d.replace(" " , "")
- num1 = int(d[8])
- num2 = int(d[10])
- risu = num1 / num2
- print(num1 , "/" , num2 , "fa" , risu)
- continue
- if "pulisci" in d.lower() :
- Space(100)
- continue
- if "" in d.lower() :
- continue
- if d.lower() in x : #Controllo se è stata già fatta e registrata
- print(x[d.lower()]) #Se sì stampo la risposta
- else : #Se no
- print("Non ho capito, cosa devo rispondere?")
- a = input(">>> ") #Chiedo all'utente cosa rispondere
- if a.lower() != "niente" :
- x[d.lower()] = a #E lo memorizzo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement