Want to make a simple program to calculate the ratio btwn 3 given numbers. For ex. Given numbers: 3,6,9 than the o/p should be 1:2:3.
If the input data is going to keep this ratio: #!/usr/bin/python print first // first, second // first, third // first The "//" forces integer division. In the general case, you have to find the greatest common denominator and then divide by that. ''' #!/usr/bin/python import sys def gcd( first, second ): """ Implements Euclid's algorithm for finding the largest common denominator of two integers. """ x = max( first, second ) y = min( first, second ) remainder = x % y while( remainder != 0 ): x = y y = remainder remainder = x % y return y if( __name__ == "__main__" ): print gcd( int( sys.argv[1] ), int( sys.argv[2] ) ) sys.exit( 0 ) '''
What language did you want to make it in?
Join our real-time social learning platform and learn together with your friends!