Итак, я пытаюсь создать чат-бот на питоне. Онлайн-идео (repl.it) — это то, что я использую для запуска кода из любого места. Он имеет цикломатический предел сложности 15. Я хотел бы сделать что-то действительно сложное, не выходя за этот предел. Возможно ли это?
import random
greeting = ["Hello!","Hi!","Hey!","Hello my name is IFuture!","How may I help you?"]
farewell = ["Bye","Bye bye","See you soon","Don't forget about me!","See you next time","See you"]
catchthat = ["I didn't catch that.","Sorry, I couldn't understand what you said.","Could you say that again?","Could you type in english?"]
notnice = ["That wasn't nice.","Next time try to say that nicer.","Try being nice.","You have more friends when you are nice."]
def run():
global greeting,farewell,catchthat
userinputa = str(input(">>>")).lower()
userinput = userinputa.split()
if "hello" in userinput or "hey" in userinput or "hi" in userinput:
print(random.choice(greeting))
elif "swear1" in userinput or "swear2" in userinput or "swear3" in userinput or "swear4" in userinput or "swear6" in userinput:
if "you" in userinput:
print(random.choice(swear back)
else:
#print(random.choice(notnice))
print("swear back")
elif "what" in userinput:
if "can" in userinput:
if "you" in userinput:
if "do" in userinput:
print("Try ?help or anything I am made to do.")
elif "is" in userinput:
try:
num1 = int(userinput[2])
num2 = int(userinput[4])
conversion = str(userinput[3])
if conversion in ["add","plus","addition","sum","+"]:
print(num1+num2)
elif conversion in ["times","multiply","*","x"]:
print(num1*num2)
elif conversion in ["divide","/"]:
print(num1/num2)
except:
print("Try using spaces for example 5*5 would be 5 * 5.")
else:
print(random.choice(catchthat))
while True:
run()
Извините за мой ужасно неэффективный код.
run
на более мелкие методы. - person Stephen C   schedule 15.08.2019swear
иback
не определены, просто используйте присягу - person kederrac   schedule 15.08.2019