python添加请求来自用户
数学语句是将x1和x2相加 python的输出是: 输入语句或E以退出程序: 然后用户输入: 加35和5 输出为: 答案:加35和5=40 如何使用python编写此输出? 输入语句或E退出程序:添加35和5python添加请求来自用户,python,python-3.x,calculator,Python,Python 3.x,Calculator,数学语句是将x1和x2相加 python的输出是: 输入语句或E以退出程序: 然后用户输入: 加35和5 输出为: 答案:加35和5=40 如何使用python编写此输出? 输入语句或E退出程序:添加35和5 回答:添加35和5=40您需要使用.split分隔字符串中包含的用户输入。 但是您应该检查用户是否使用了add和if,以确保用户语句符合您的要求。您的问题是什么?print是什么:-它不是python?欢迎使用,请检查 action = input("Enter the statemen
回答:添加35和5=40您需要使用.split分隔字符串中包含的用户输入。
但是您应该检查用户是否使用了add和if,以确保用户语句符合您的要求。您的问题是什么?print是什么:-它不是python?欢迎使用,请检查
action = input("Enter the statement [add] or E to exit the program: ")
if action == "add":
x1 = int(input("enter the first number: "))
x2 = int(input("enter the second number: "))
print("Answer: Add {} and {} = {}". format(x1,x2,x1+x2))
elif action == "E" or action == "e":
# exit action
exit("Goodbye")
else:
# unexpected action
exit("Error: invaild action {}".format(action))
action = input("Enter the statement [add] or E to exit the program: ")
if action == "add":
x1 = int(input("enter the first number: "))
x2 = int(input("enter the second number: "))
print("Answer: Add {} and {} = {}". format(x1,x2,x1+x2))
elif action == "E" or action == "e":
# exit action
exit("Goodbye")
else:
# unexpected action
exit("Error: invaild action {}".format(action))