# 如何创建一个接受 2 个数字并返回正确计算的计算器程序？（python）[关闭]

[英]How do I create a calculator program that takes 2 numbers and returns the correct calculation?(python) [closed]

• 接受两个数字和一个符号作为参数
• 并返回正确的计算（然后必须保存返回的值）
• 作为 function 之外的变量，然后打印
``````#I have no clue what a parameter is
number1 = input("1st number")
number2 = input("2nd number")
#how do you do a list to choose the symbol from e.g like *, +, -, /, MOD, DIV
#i dont know what the rest of the instructions mean
``````

``````from operator import add, sub, mul, truediv

operations = {'+':add, '-':sub, '*':mul, '/':truediv}

def calculate(num1, num2, op):
return operations[op](num1, num2)

print('2 + 3: ', calculate(2, 3, '+'))
print('2 - 3: ', calculate(2, 3, '-'))
print('2 * 3: ', calculate(2, 3, '*'))
print('2 / 3: ', calculate(2, 3, '/'))
``````

``````def calculate(number1, number2, operator)
result = 0

if operator == '+':
result = number1 + number2
elif operator == '-':
result = number1 - number2
elif operator == '*':
result = number1 + number2
elif operator == '/':
result = number1 / number2
else:
return 'Wrong input!'
return result

a = int(input('First number: '))
o = input('Operator: ')
b = int(input('Second number: '))

print(calculate(a, b, o))
``````

[英]how do I create a program that takes random tuples from a list of tuples and generates a basic plot in python?

2020-12-10 08:36:22 1 42   tuples

[英]How can I create a function in Python that takes a list of numbers and an integer?

[英]Please correct the code for my python calculator program

2021-01-10 12:34:54 1 22   python

[英]How do i create a tipping program for python?

2013-04-18 15:42:07 4 4558   python
Python-如何创建带有参数的新装饰函数？

[英]Python - how do I create a new decorated function that takes arguments?

[英]how do I write a program that takes a list of strings as input and returns a dictionary, containing an index of the words to the matching strings

[英]Calculator program returns tkinter error in python

[英]How do I distribute a python program with the correct modules?