Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding greatest common divisor (assignment misgraded, I desperately need your help)
    primarykey
    data
    text
    <p>I had an assignment (homework) as follows:</p> <blockquote> <p>Write a program which enters two positive integers a and b from the keyboard. Also write a recursive function for determining the gcd (greatest common divisor) of a and b using Euclid’s algorithm. According to this algorithm if the first number is divisible by the second one then thesecond one is the gcd. If this is not the case then the gcd of the second number and the remainder of a=b has to be determined. The result should be printed on the screen outside of the function.</p> </blockquote> <p>Here is my solution:</p> <pre><code>a=int(input("Enter the first number: ")) b=int(input("Enter the second number: ")) def GCDfinder(m,n): z=abs(m-n) if (m-n)==0: return n else: return GCDfinder(z,min(m,n)) print (GCDfinder(a,b)) </code></pre> <p>I got 50% for this answer. I think the teacher's assistant who graded this does not know about what she does. Her comment is as follows:</p> <blockquote> <p>That is not the method described in the assignment. You should first check if a%b==0 then return b. Or return gcd(b, a%b) Also check that the input is positive and a>b</p> </blockquote> <p>1-) The method that I used was based on Euclid's theorem. <a href="http://en.wikipedia.org/wiki/Euclidean_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Euclidean_algorithm</a></p> <p>2-) There is absolutely no need to check a>b and there is also no need to check whether the input is positive or not, because I used abs()</p> <p>Didn't TA misgrade the assignment? Or am I wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload