Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
286 views
in Computer by (49.5k points)
closed by

Write a program that accepts numerator and denominator of a fractional number and calls a user defined function mixed Fraction() when the fraction formed is not a proper fraction. The default value of denominator is 1. The function displays a mixed fraction only if the fraction formed by the parameters does not evaluate to a whole number.

1 Answer

+1 vote
by (51.9k points)
selected by
 
Best answer
#Function to display mixed fraction for an improper fraction 

#The requirements are listed below: 

    #1. Input numerator and denominator from the user. 

    #2. Check if the entered numerator and denominator form a proper 

          #fraction. 

    #3. If they do not form a proper fraction, then call #mixedFraction(). 

    #4. mixedFraction()display a mixed fraction only when the fraction 

         #does not evaluate to a whole number. 

def mixedFraction(num,deno = 1): 

       remainder = num % deno 

#check if the fraction does not evaluate to a whole number 

       if remainder!= 0: 

            quotient = int(num/deno) 

            print("The mixed fraction=", quotient,"(",remainder, "/", 

deno,")") 

     else:

        print("The given fraction evaluates to a whole number") 

#function ends here 

num = int(input("Enter the numerator: ")) 

deno = int(input("Enter the denominator: ")) 

print("You entered:",num,"/",deno) 

if num > deno:         #condition to check whether the fraction is 

improper      

        mixedFraction(num,deno)     #function call 

else: 

        print("It is a proper fraction") 

Output: 

   Enter the numerator: 17 

   Enter the denominator: 2 

   You entered: 17 / 2 

   The mixed fraction = 8 ( 1 / 2 )

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...