我需要一个程序,从用户(文本)获得一行输入,然后以文本形式输出(我在下面写了一个例子)
我尝试了如果但是它只接受一行代码,如果我写了一个没有定义的单词,它会毁了其他的。你知道吗
class meaning():
def shortcutA (self):
print ("ice cream")
def shortcutB (self):
print ("Choclet cake")
def main():
m = meaning()
if input() == "a":
print("your code is: ")
m.shortcutA()
elif input() == "b":
print("your code is: ")
m.shortcutB()
else :
print ("unrecognized")
print ("Please enter the words :")
if __name__ == "__main__":
main()
我希望当我进入a b时,结果是
ice cream
Choclet cake
谢谢你。你知道吗
我建议这样的计划
您需要修改
if
输入语句。 如果要根据空格分隔的输入输出,请使用以下命令:希望这有帮助。。你知道吗
我们可以使用for循环遍历单词中的输入。你知道吗
产生:
相关问题 更多 >
编程相关推荐