View Single Post
Old Feb 2nd, 2006, 3:59 PM   #9
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Volkan
hmm i looped it not usign a conventional loop as that method using the WHILE tag didnt work,
That may have been a mistake on my part. Somehow I missed of the colon at the end of the condition. Try the following (fixed) code:
answer = 0

while answer != 2:
    print """Choose an option:
    1. Continue the loop.
    2. Exit the loop."""

    answer = input("> ")
Quote:
Originally Posted by Volkan
also i noticed no "indentation" which many tutorials and people talk about.
Indentation is a concept vital to Python. Much of Python's syntax hinges around it.

Simply put, this is indented code:
print "Starting test"
x = 1
if x == 1:
    print "x == 1"
print "Ending test"
And this is not:
print "Starting test"
x = 1
if x == 1:
print "x == 1"
print "Ending test"
The indented line in the first example (print "x == 1"), tells Python that this line of code 'belongs' to the if statement above it. The line of code will execute only if the condition is correct, if the value of x is 1.

Without indentation, Python has no way of telling what lines belong to the if statement.
Quote:
Originally Posted by Volkan
i get no indentation i used PYTHON IDLE GUI version to make this.
Likely Idle automatically indents things for you.

Quote:
Originally Posted by Volkan
print ""
choice = raw_input("Calculate More? Y or N: ").upper()
if choice == 'Y':
calculator()

that is what i used to get it to go back and do more calculation.
You're using a technique called recursion, as opposed to using a while loop, which is called iteration. The major disadvantage with recursion in Python is that it's finite. Python can only handle a certain number of recursions (although this is a large number) before it runs out of memory. With iteration, you can loop as many times as needed.
Arevos is offline   Reply With Quote