I just started to learn Python before a week or so and i found this example and rewrited it in Notepad++ (btw it was really painfull to figure out how to connect Notepad++ with python.exe but i like notepad++ more than Python GUI)
and this program just wont work nor in the Notepad++ nor in the Python GUI (i use 2.6 btw)
# Calculator Program (Page 17 Python Tutorial)
# NO CODE IS REALLY RUN HERE,ITS ONLY TELLING US WHAT WE WILL DO LATTER
# Here we will define our functions
# This prints the main menu,and prompts for a choice
import time # Import time module - Its needed to pause program to see result
def menu():
# print what options we have
print "Welcome to the calculator.py"
print "Your options are:"
print " "
print "1) Addition"
print "2) Substraction"
print "3) Multiplication"
print "4) Division"
print "5) Quit Calculatory.py"
print " "
return raw_input("Choose your option: ")
# This add two numbers given
def add(a,b):
print a ,"+", b , "=" , a + b
# This substracts two numbers
def sub(a,b):
print a ,"-" , b ,"=" , a-b
# This multiplies two numbers
def mul(a,b):
print a ,"*", b , "=" , a*b
# This divides two numbers
def div(a,b):
print a , "/" , b ,"=" , a/b
# NOW THE PROGRAM REALLY STARTS,AS CODE IS RUN
loop = 1
choice = 0
while loop == 1:
choice = menu()
if choice == 1:
add(raw_input("Add this: "),raw_input("to this: "))
elif choice == 2:
sub(raw_input("Subdivide this: "),raw_input("by this: "))
elif choice == 3:
mul(raw_input("Multiply this: "),raw_input("by this: "))
elif choice == 4:
div(raw_input("Divide this: "),raw_input("by this: "))
elif choice == 5:
loop = 0
print "Thank you for using Calculator.py"
raw_input("Press ENTER to exit")
time.sleep(5)
i get error message at add(raw_input("Add this: "),raw_input("to this: "))
The code is exactly as in tutorial :/
thx in advance
regards Perun