Description:
This is a very simple calculator using Python 3.3.2. It uses the command prompt, similar to Visual Basic.Net's console application.
Notes:
You can easily convert this to compile with Python 2, just change input() to raw_input()
Plans:
I plan to properly parse the numeric datatypes. Currently I'm just using int([string]), which is fine if the user enters in a numeric data type, but if the user enters in a non-numeric character then it will crash the program.
Source:
Python Code:
#The add, subtract, multiply, and divide functions
def add(x, y):
return x + y
def sub(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
#Infinite loop
main = True
while main == True:
#Get values for the x and y parameters for the functions above.
x = int(input("Value 1: "))
y = int(input("Value 2: "))
getoperation = True
while getoperation == True:
#The print out should be:
#What would you like to do?
#Add = +
#Subtract = -
#Multiply = *
#Divide = /
#
#
operation = input("What would you like to do?\nAdd = +\nSubtract = -\nMultiply = *\nDivide = /\n\n")
#Get the operation and preform the function accordingly
if operation == "+":
getoperation = False
print (str(x) + " + " + str(y) + " = " + str(add(x, y)))
elif operation == "-":
getoperation = False
print (str(x) + " - " + str(y) + " = " + str(sub(x, y)))
elif operation == "*":
getoperation = False
print (str(x) + " * " + str(y) + " = " + str(multiply(x, y)))
elif operation == "/":
getoperation = False
print (str(x) + " / " + str(y) + " = " + str(divide(x, y)))
else:
#If the user entered in something other than +-*/ then repeat
print ("Invalid Input")