Reputation: 3
I am creating a chatbot based on The Talking NPC game in Roblox
it crashes after i type hello
error code
Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), main.dict) File "", line 21, in TypeError: can only concatenate str (not "int") to str
code
import random
print(" AI created by MThien \n")
sys = input(" [ System ]: My name is: ")
sys2 = 0
sys4 = 0
while True:
user = input(" [ " + str(sys) + " ]: ")
sys1 = random.choice(["Hello!", "Hello there", "Hello " + str(sys), "Sup!", "Howdy!", "Wassup!"])
sys2 = random.choice(["Wrong number, sorry.", "Apologize, my visitor is just having a mental breakdown."])
sys3 = random.choice(["What?", "?", "Sorry?", "I don't understand", "I don't get it.", "Sry my English is bad.", "Sry my IQ is still low."])
sys4 = random.choice(["...", "Stop it.", "You've already said hello to me several times.", "That's enough for greeting me."])
if user == "hello":
print(" [ AI ]: " + str(sys1))
sys4 += 1
if sys4 >= 5:
print(" [ AI ]: "+ str(sys4))
elif user == "/call":
print(" [ Telephone ] : *dialing*")
time.sleep(2)
print(" [ Telephone ] : The number you're calling isn't registered.")
time.sleep(1)
print(" [ Telephone ] : *call ended*")
elif user == "/call 911":
print(" [ Telephone ] : *dialing*")
time.sleep(2)
print(" [ Telephone ] : 911, what's your emergency?")
time.sleep(1)
print(" [ AI ]: "+ str(sys1))
time.sleep(1)
print(" [ Telephone ] : *call ended*")
sys2 += 1
if sys2 == 3:
time.sleep(3)
print(" [ FBI ] : FBI, OPEN UP!")
time.sleep(5)
print(" [ System ]: You were kicked from this experience: You got arrested!")
break
else:
print(" [ AI ]: " + str(sys3))```
Upvotes: 0
Views: 63
Reputation: 866
You are overwriting your values when you likely don't intend to. Let's take a user input of hello
for example. Prior to reaching this statement, you have two statements being
sys4 = 0
sys4 = random.choice(["...", "Stop it.", "You've already said hello to me several times.", "That's enough for greeting me."])
Once you hit that second statement, sys4 is now a string. You then get to sys4 += 1
, where you are trying to add 1
to a string. Python does not support this, and it is obvious you were trying to add 1
to the integer version of sys4
and not the string version. However, sys4
no longer exists as an integer.
Properly name your variables and the problem should go away.
Also, the tags for android
artifical-intelligence
, and roblox
are not relevant to this question.
Upvotes: 1