Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first python script "The Calculator from Compton"
#1
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 "----------------------------------------"
Reply
#2
For the choice = input you should put raw_input
Reply
#3
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
Reply
#4
(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. Thumbsup
Reply
#5
(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. Thumbsup

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
Reply
#6
(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
Reply
#7
nice work keep working on it
[Image: mypegif2.gif]
Reply
#8
thanks allot indeed, was working on some code this may be useful for my project thanks!
Reply
#9
Thank you very much for this unique ghetto calculator
Confused
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 2,028 09-30-2019, 12:59 AM
Last Post: samsmith001
  How to Run a Python Script..? Need Help aloneak 4 1,735 05-03-2012, 06:55 AM
Last Post: Rhynorater
  Simple Python Python Compiler Canoris 21 9,345 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,719 12-11-2010, 04:13 PM
Last Post: Bursihido
  [Tutorial] Advanced Tkinter Calculator uber1337 8 5,705 04-06-2010, 11:51 AM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 1 Guest(s)