打印("你好!"(
user_name=输入("你叫什么名字?"(
打印("你好,"+用户名称+"\n"(
打印("你好吗?"(
打印(+user_name+"\n"(
good=";快乐的";
good=";悲伤的";
good=";自杀;
如果好的话!="快乐":打印("那是我的,"+用户名+"\n"(
elif good=";悲伤":打印("对不起,我是僵尸网络,"+user_name+"\n"(
elif good=";"自杀":print("1-800(‘国家自杀预防’("+user_name+"\n〃(
您没有得到提示,因为您没有要求任何输入,并且您可能想要为if-else-定义一个基本情况
print("hello!n")
user_name = input("what is your name?n")
print("hello, " + user_name + "n")
mood = input("how are you doing? %s n" % user_name)
if mood == "happy": print("thats aswesome,"+ user_name + "n")
elif mood == "sad": print("Am sorry but am a botnet,"+ user_name + "n")
elif mood == "suicide": print("1-800 ('national Suicide Prevention')"+ user_name + "n")
else: print("Sorry I don't understand it")
我想这是解决它的多种方法之一:
print("hello!n")
user_name = input("what is your name?n")
print("hello, " + user_name + "n")
print("how are you doing, " + user_name + "?n")
good = input(""" 1. happy
2. sad
3. suicide
""")
if good == "happy" or good == "1": print("thats aswesome, "+ user_name + "n")
elif good == "sad" or good == "2": print("I Am sorry but I am a bot, "+ user_name + "n")
elif good == "suicide" or good == "3": print("1-800 ('national Suicide Prevention') "+ user_name + "n")
结果:
hello!
what is your name?
Jack
hello, Jack
how are you doing, Jack?
1. happy
2. sad
3. suicide
2
I Am sorry but I am a bot, Jack
hello!
what is your name?
Jack
hello, Jack
how are you doing, Jack?
1. happy
2. sad
3. suicide
happy
thats aswesome, Jack