I've completely rewritten a calculator I wrote to help me learn Python.
After someone told me about the def command I reliesed that I could
make the program much better, but there is a very anoying problem which
ocours when I run the program.
Here is the code
<code>
# IMPOSRTS #
import sys
import os
# DEF'S #
def print_intro():
os.system('clear')
print "Welcome to Calc v 0.1a"
print "----------------------"
def main():
print_intro()
while True:
prompt_user()
def prompt_user():
userinput = input(">")
def fib(n): # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
print
def quit():
sys.exit()
# PROGRAM FLOW
main()
</code>
Now when I run this program and I type in a command which I have no
code for e.g. "pi" (which is 3,14....) I get the error message
"NameError: name 'pi' is not defined" and then the program quits.
I'm creating this program for my own use but naturally sometimes I
would make spelling mistakes (being a dyslexic and all) and so having a
long error message and having the program quit is more then a bit
irritating. It would be much more preferable if the program simply
wrote "Command not recognised" and then kept going. Is this possible?