+ 5

# What's wrong with this code?

I am trying to calculate the Greatest Common Divisor (GCD) for every pair of numbers inputted. Thereafter, i want to ouput the numbers not separated by a comma, and there should be in a single output line with the GCD. I want my output to look like this (sample input & output for test case T = 4): 2, 1 GCD 1 3, 4 GCD 1 5, 5 GCD 5 10, 4 GCD 2 Please help. Here's my output for a trial i did on Jupyter(Anaconda). It gives an error where am i going wrong. Please help. here is a screenshot for the trial i ran on Jupyter: https://ibb.co/6sNqf1g (uploaded on imgbb Here is the full code: https://code.sololearn.com/cN1XtZxHOB35/?ref=app

10 Answers

+ 6

gcd = gcd(a,b) # this will shadow gcd() function so on next call it is 'with variable with braces' is not function call with parameters.. .
Take different names for function and variable.

+ 4

Yes, i think you've put it quite perfectly Maisu, how can i loop through my conditions and using standard code. The code i wrote is literally junk lol. So yes, thats the answer

+ 3

Jayakrishna🇮🇳 thanks you for the correction🙏 . I have changed and it works fine. Now time to work on more features.

+ 3

Hie guys. So still on this question, actually i got it from Hackerearth its a practice question. I have manage to solve all the test cases and a one more test block of three needed to completely submit it. I dont know where I'm going wrong, please help.
The link to the original question is 👇
https://www.hackerearth.com/practice/algorithms/dynamic-programming/2-dimensional/practice-problems/algorithm/gcd-game-11/
So i created two projects both serving the same purpose.
1. It is for submission purposes only and its not user friendly but I have written comments in it. It's link is 👇
https://code.sololearn.com/cN1XtZxHOB35/?ref=app
2. The second one is easier to work with as a user, it gives out prompt messages when working with it and here is its link below 👇
https://code.sololearn.com/cew3r1yZW7Jk/?ref=app

+ 3

Maisu, you mean i shouldn't have imported the gcd module🤔🤔🤭.. Ooops that's my bad.

+ 3

I guess I would wrap the conditions in a while loop. Then I would create a control variable and you change its value depending if you want to repeat or not.

+ 3

Sure thing Maisu, let me try the work around

+ 1

Why do you import the gcd form math ? I though the challenge was to compute it by yourself.

+ 1

Actually, you want to find a way how to loop through your conditions ?