loop = 1
choice = 0
while loop == 1:
print "1) Addition"
print "2) Subtraction"
print "3) Division"
print "4) Multiplication"
print "5) Exit"
choice = input("Choose your operation: ")
if choice == 1:
ax = input("Add this: ")
ay = input("To this: ")
print ax, "+", ay, "=", ax + ay
if choice == 2:
sx = input("Subtract this: ")
sy = input("From this: ")
print sx, "-", sy, "=", sx - sy
if choice == 3:
dx = input("Divide this: ")
dy = input("By this: ")
print dx, "/", dy, "=", dx / dy
if choice == 4:
mx = input("Multiply this: ")
my = input("With this: ")
print mx, "x", my, "=", mx * my
elif choice == 5:
loop = 0
print "----------------------------------------"
print "----------------------------------------"
For the choice = input you should put raw_input
(10-08-2009, 08:12 PM)g4143 Wrote: [ -> ]This is how you should create a calculator in Python...use its functionality
http://www.hackforums.net:80/showthread....python+cal
Well maybe they're just starting out on python. The title DOES say "My First python script" after all. This is definitely something basic, but nonetheless, it's good for a beginner. Good job on your first script.
(10-09-2009, 08:00 AM)theEND Wrote: [ -> ]Well maybe they're just starting out on python. The title DOES say "My First python script" after all. This is definitely something basic, but nonetheless, it's good for a beginner. Good job on your first script.
This isn't a critique, its just a pointer to some of the really neat things you can accomplish with Python. Python, along with a few other interpreted languages, offer some unique features that can make programming a joy...this is one of them...G4143
(10-08-2009, 08:12 PM)g4143 Wrote: [ -> ]This is how you should create a calculator in Python...use its functionality
http://www.hackforums.net:80/showthread....python+cal
I made one with funcions alrdy, but i like the this one better. more clear, but here is the one I made with functions
Code:
def menu():
print "---------------------------------------------------"
print " Welcome To Nevets04's Calculator"
print "---------------------------------------------------"
print "1) Addition"
print "2) Subtraction"
print "3) Multiplication"
print "4) Division"
print "5) Quit"
return input ("Choose an operation: ")
def add(a,b):
print a, "+", b, "=", a + b
def sub(a,b):
print a, "-", b, "=", a - b
def mul(a,b):
print a, "x", b, "=", a * b
def div(a,b):
print a, "/", b, "=", a / b
loop = 1
choice = 0
while loop == 1:
choice = menu()
if choice == 1:
add(input("Add this: "), input("To this: "))
elif choice == 2:
sub(input("Subtract this: "), input("From this: "))
elif choice == 3:
mul(input("Multiply this: "), input("With this: "))
elif choice == 4:
div(input("Divide this: "), input("By this: "))
elif choice == 5:
loop = 0
nice work keep working on it
thanks allot indeed, was working on some code this may be useful for my project thanks!
Thank you very much for this unique ghetto calculator