简体   繁体   English

我可以要求用户输入任何基本的算术方程,而不必要求计算每个单独的数字吗?

[英]Can I ask the user to input any basic arithmetic equation without having to ask for every individual number to be computed?

I am a complete beginner in coding.我是编码的完整初学者。 I want to make a simple math calculator using Python.我想用 Python 做一个简单的数学计算器。 Instead of the traditional method of asking the user to input 2 separate integers (in this example addition)而不是要求用户输入 2 个单独的整数的传统方法(在此示例中添加)

num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
total = num1 + num2
print(total)

I would like the user to immediately input我希望用户立即输入

1+1

or any other simple math that may involve one or a combination of the following: addition, subtraction, multiplication, division.或任何其他可能涉及以下一项或多项的简单数学:加法、减法、乘法、除法。 Is it possible to do so?有可能这样做吗?

you could also separate the input into a list.您还可以将输入分成一个列表。 For example, when you input "1 + 1" there are functions in Python to separate all the characters in the list.例如,当您输入“1 + 1”时,Python 中有函数可以分隔列表中的所有字符。 It can make it ["1", "+", "1"].它可以使它成为[“1”,“+”,“1”]。 With this, you can read each individual character and use them like input[2] to find the operation.有了这个,您可以读取每个单独的字符并像 input[2] 一样使用它们来查找操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在条件后要求用户输入? - How can I ask the user for an input after a conditional? 如何通过 Windows 中的终端在 python 中请求用户输入? - How can I ask for user input in python through the terminal in windows? Python要求用户输入没有换行符? - Python ask for user input without a newline? 我如何要求用户输入时间 - How do I ask the user to input time Python Def 函数的用户输入,我需要询问一个数字,然后使用该数字向下计数或向上计数 - Python user input for Def functions, I need to ask for a number and then use that number to either count down or factor up 我怎样才能问用户 6 次? - How can i ask the user 6 times? 编译器不要求任何输入 - compiler doesnt ask for any input 我可以向用户询问一个号码,并将对应号码的图像粘贴到一个空白图像中吗? - Can I ask the user for a number, and paste the image of the correspondant number into a blanc image? 如何让一个 python 文件要求用户输入,然后将此输入传递给第二个 .py 文件? - How can I make one python file ask for user input and then pass this input to a second .py file? 如何从用户那里获取输入,将它们放入列表中,然后从中随机选择一个,而无需多次询问 - How to get input from user, put them into a list and then choose a random one from them without having to ask multiple times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM