Okay...I'm back again for the next program...here's what i have so far

print "Euclid's Method"

a= raw_input(("Enter first number   "))

b= raw_input(("Enter second number   "))

def euclid(a,b):
    while b != 0:
        a, b = b, a%b
        return a

My question is, how do I get it to print out the proper number?

If i use

print a

, it shows the original value for a
I also tried

print euclid(a, b)

but this kicked back an error

Traceback (most recent call last):
  File "C:/Users/Tony/Documents/Module 2/euclid", line 11, in <module>
    print euclid(a, b)
  File "C:/Users/Tony/Documents/Module 2/euclid", line 9, in euclid
    a, b = b, a%b
TypeError: not all arguments converted during string formatting

Thanks for any help

Recommended Answers

All 6 Replies

do euclid(int(a), int(b))

The print, one place is enough.

Cheers and Happy coding

Ok, i used the int code...but it returns the second input, not the correct answer. I must have written this incorrectly.

This is what I need to do...

Write a function that implements Euclid’s method for finding a common factor of two numbers. It works like this:

1. You have two numbers, a and b, where a is larger than b
2. You repeat the following until b becomes zero:
3. a is changed to the value of b
4. b is changed to the remainder when a (before the change) is divided by b (before the change)
5. You then return the last value of a

Hints:

1. Use a and b as parameters to the function
2. Simply assume that a is greater than b
3. The remainder when x is divided by z is calculated by the expression x % z
4. Two variables can be assigned to simultaneously like this: x, y = y, y+1. Here x is given the value of y (that is, the value y had before the assignment) and y is incremented by one

Did I write the code wrong?

Return must not be inside the while but after exit from while.

Thanks. I fixed it. You guys are a ton of help. I appreciate it a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.