[英]how can I do the action based on user input in python
I have this code我有这个代码
phrase = input("Enter your message: ")
if 'hello' in phrase:
print('Hello, Human')
if 'what is your favorite color' in phrase:
print("It's blue")
else:
print('unavailable')
how can it reply based on user like if he say hello and then what is your favorite color it will reply hello then it's blue like below:它如何根据用户回复,比如如果他打招呼,然后你最喜欢的颜色是什么,它会回复你好,然后是蓝色,如下所示:
Enter your message: hello, what is your favorite color
Hello, Human
It's blue
and that's okay but what if I want to automatically change like if he say what is your favorite color and then hello it will reply it's blue and then hello so the output should like this:没关系,但是如果我想自动更改,就像他说你最喜欢的颜色是什么然后你好它会回复它是蓝色然后你好所以 output 应该是这样的:
Enter your message: what is your favorite color, hello
It's blue
Hello, Human
but not like this:但不是这样的:
Enter your message: what is your favorite color, hello
Hello, Human
It's blue
Your question is a bit too unspecific.. please specify it a bit more.你的问题有点太不具体了..请再具体一点。
For the favorite color, since the user might ask something like "what's your favorite color", your program won't respond with blue because it's different from "what is your favorite color", so just have the program check for "favorite color".对于最喜欢的颜色,由于用户可能会问“你最喜欢的颜色是什么”之类的问题,你的程序不会用蓝色响应,因为它不同于“你最喜欢的颜色是什么”,所以只需让程序检查“最喜欢的颜色” .
phrase = input("Enter your message: ")
if 'hello' in phrase:
print('Hello, Human')
elif 'favorite color' in phrase:
print("It's blue")
else:
print('unavailable')
phrase = input("Enter your message: ")
if 'hello' in phrase:
print('Hello, Human')
phrase1 = input('Enter your message: ')
if phrase1 == 'what is your favorite color':
print('its blue')
elif 'what is your favorite color' in phrase:
print("It's blue")
phrase2 = input('Enter your message: ')
if phrase2 == 'hello':
print('hello human')
else:
print('unavailable')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.