On 20/07/12 00:17, Prasad, Ramit wrote:
def num_diag(var): ans = 0 if var <= 3: print("No diagonals.") else: for i in range(num_sides - 3): ans = ans + i return (((var - 3)*2) + ans) num_sides = (int(raw_input("Enter sides: "))) num_diag(num_sides)
NameError: global name 'num_sides' is not defined `for i in range(num_sides - 3):` Change num_sides to var.
It should work without, because it will pick up the global variable definition. It's probably not working the way it was intended to, but it should work... But changing it to use the argument would definitely be better. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor