Control Structures (Quotient Calculator)

Back To The Index Quotient

An interactive program which reads two numbers and displays their quotient

In [ ]:
###################################################
#  Filename : divide_numbers                      #
#  Purpose : To demonstrate console input and     #
#   usage of the following control structures     #
#            1. if elif else                      #
#            2. while loop                        #
#  Author : Niel S.                               #
#  The English Tea Company LLC                    #
###################################################

def main():
    #Read data from command line
    X = input ("Enter Numerator: ")
    Y = input ("Enter Denominator: ")
    
    #While there is a numeric input
    while( X.isnumeric() and Y.isnumeric()):
        X = float (X)
        Y = float (Y)
        Q = None
        if Y != 0:
            Q = X/Y
            print ('Quotient: ',Q)
        else:
            print ('Error: Division by 0 is not defined.')
        X = input ("Enter Numerator: ")
        Y = input ("Enter Denominator: ")
    
    print ('Good Bye')
            
   

if __name__ == '__main__':
    main()

Question: Following Question must be investigated: Why is following chunk of code needed ? X = float (X) Y = float (Y)

Back To The Index