【发布时间】:2017-09-28 18:55:56
【问题描述】:
这个程序应该是一个计算器。当我运行程序时,它会这样打印操作
我不确定如何解决这个问题。我一直在尝试制作一个在终端中运行几天的简单计算器,但似乎没有任何效果。我想我需要重新定义操作 var 来打印它。我不知道该怎么做。
#The functions of this program #
def add(num1, num2):
return (num1 + num2)
def sub(num1,num2):
return (num1 - num2)
def mul(num1, num2):
return (num1 * num2)
def div(num1, num2):
return (num1 / num2)
##The variables of this program ##
num1 = input ("Number 1: ")
num2 = input ("Number 2: ")
operation = input ("Operation: ")
###The if statements of this program ###
if operation == "add":
(num1 + num2)
elif operation == "sub":
(num1 - num2)
elif operation == "mul":
(num1 * num2)
elif operation == "div":
(num1 / num2)
####The final code to print the product ####
print operation
【问题讨论】:
标签: python calculator