New user needs help
wes weston
wweston at att.net
Sat Feb 21 11:13:52 EST 2004
John,
If you really want a var in a function to be a global
version, you need to use the "global" stmt.
a = 4
def foo():
global a = x
It's probably a good idea to put all global vars at the
top of your file right after your import stmts.
wes
John wrote:
> I am new to using Python. Everytime I run this program it prints "The lowest
> common factor is 0", no matter what numbers I use. Can anybody see anything
> wrong with my program? Thanks in advance.
>
>
>
> def getnum1(a):
> a = input("What is the first number?")
> if a == 0:
> getnum1(a)
> def getnum2(b):
> b = input("What is the second number?")
> if b == 0:
> getnum2(b)
> def euclid(num1, num2, num3, num4):
> if num1 < num2:
> num3, num4 = num1, num2
> num1, num2 = num4, num3
> euclid(num1, num2, num3, num4)
> elif num2 != 0:
> num3, num4 = num1, num2
> num1 = num4
> num2 = num3 % num4
> euclid(num1, num2, num3, num4)
> else:
> print "The lowest common factor is: ", num1
> a = 0
> getnum1(a)
> b = 0
> getnum2(b)
> x, y = 2, 100
> euclid(a, b, x, y)
>
>
More information about the Python-list
mailing list