Posts: 401
Threads: 141
Joined: Oct 2009
Reputation:
5
10-08-2009, 06:52 PM
(This post was last modified: 10-08-2009, 06:54 PM by nevets04.)
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 "----------------------------------------"
Posts: 264
Threads: 48
Joined: Oct 2009
Reputation:
1
For the choice = input you should put raw_input
Posts: 119
Threads: 16
Joined: Oct 2009
Reputation:
4
This is how you should create a calculator in Python...use its functionality
http://www.hackforums.net:80/showthread....python+cal
Slackware 13/ArchLinux - C/Assem/Python
Posts: 10
Threads: 1
Joined: Oct 2009
Reputation:
0
10-09-2009, 08:00 AM
(This post was last modified: 10-09-2009, 08:02 AM by theEND.)
(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.
Posts: 119
Threads: 16
Joined: Oct 2009
Reputation:
4
(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
Slackware 13/ArchLinux - C/Assem/Python
Posts: 401
Threads: 141
Joined: Oct 2009
Reputation:
5
(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
Posts: 32
Threads: 5
Joined: Oct 2009
Reputation:
0
nice work keep working on it
Posts: 7
Threads: 0
Joined: Oct 2009
Reputation:
0
thanks allot indeed, was working on some code this may be useful for my project thanks!
Posts: 83
Threads: 11
Joined: Oct 2009
Reputation:
3
Thank you very much for this unique ghetto calculator
|