사용자가 뭄바이의 날씨는 어떻냐고 물어보고 봇은 뭄바이의 날씨가 놀랍다 고 답해야합니다.
# i want the %s in the if statement to be blank for user to input his city and ask for weather
def chatbot(n):
if n=='whats the weather in %s': #the user can enter anything in place of %s
print('the weather in %s is amazing')#%s means like the user enter whats the weather in mumbai
print("BOT: HEY IM CHATBOT MAY I KNOW YOUR NAME?")
a=input('YOU:')
print("BOT: Hi",a.upper())
while True:
print("BOT: ASK ME SOMETHING",a.upper(), "\U0001F642 OR PRESS q TO EXIT!")
n=input("YOU:").lower()
if n != 'q':
chatbot(n)
else:
print("BOT: BYE :)")
break
내 서식 오류를 이해하고 죄송합니다. :)
이것은 %
연산자를 사용하여 %s
자리 표시자를 대체 하지만이 솔루션은 chatbot()
메서드에 전달 된 문자열의 마지막 단어가 도시 이름 인 것에 의존합니다.
def chatbot(n):
city = n.split(" ")[-1]
if n=='whats the weather in %s' % city:
print('the weather in %s is amazing' % city)
chatbot("whats the weather in mumbai")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다