Question

Project: Proper Fractions, Improper Fractions, and Mixed Fractions Problem Description Proper fractions, improper fractions, and mixed...

Project: Proper Fractions, Improper Fractions, and Mixed Fractions

Problem Description

Proper fractions, improper fractions, and mixed fractions are defined at http://www.ltcconline.net/greenl/courses/187/b/impropermixed.htm. Write a program that prompts the user to enter the numerator and denominator of a fraction number and determines whether it is a proper fraction and improper fraction. For an improper fraction number, display its mixed fraction in the form of a + b / c if b % c is not zero; otherwise, display only the integer.

Here are sample runs of the program

Sample 1

Enter a numerator: 16

Enter a denominator: 3

16 / 3 is an improper fraction and its mixed fraction is 5 + 1 / 3.

Sample 2

Enter a numerator: 6

Enter a denominator: 7

6 / 7 is a proper fraction

Sample 3

Enter a numerator: 6

Enter a denominator: 2

6 / 2 is an improper fraction and it can be reduced to 3

Homework Answers

Answer #1

Solution:

Here is the code for the above requirement in Python 3 programming language:

if __name__ == "__main__":
  
# Take inputs from user
  
numerator = int(input("Enter a numerator: "))
denominator = int(input("Enter a denominator: "))
  
# To avoid the divide by 0 error
  
if denominator == 0:
print('Denominator cannot be 0')
  
# 0 divided by any number is 0
  
elif numerator == 0:
print('0/{} is a proper fraction with value 0'.format(denominator))
  
else:
  
if numerator == denominator:
print('{}/{} is a proper fraction with value 1'.format(numerator,denominator))
  
elif numerator < denominator:
print('{}/{} is a proper fraction'.format(numerator,denominator))
  
else:
  
# divmod() is an in-built function which takes input in the form of numerator and denominator and returns the quotient and remainder
  
quotient,remainder = divmod(numerator,denominator)
  
if remainder == 0:
print('{}/{} is an improper fraction and it can be reduced to {}'.format(numerator,denominator,quotient))
  
else:
print('{}/{} is an improper fraction and its mixed fraction is {} +{}/{}'.format(numerator,denominator,quotient,remainder,denominator))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
In Java: (Area of a convex polygon) A polygon is convex if it contains any line...
In Java: (Area of a convex polygon) A polygon is convex if it contains any line segment that connects two points of the polygon. Write a program that prompts the user to enter the number of points in a convex polygon, then enter the points clockwise, and display the area of the polygon. Sample Run Enter the number of points: 7 Enter the coordinates of the points: -12 0 -8.5 10 0 11.4 5.5 7.8 6 -5.5 0 -7 -3.5...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I feel like I know how to write that. What I'm having trouble with is implementing two files the professer gave us. I would appreicate any help in understanding their purpose as in if Im supposed to take information from those files or give it information. Thank you! I have attatched the homework instructions and the two files given. Implementation The main program, called calculator.cpp...
Which of these fractions is the multiplicative inverse of 3/4? 1. 4/3 2. - 4/3 3....
Which of these fractions is the multiplicative inverse of 3/4? 1. 4/3 2. - 4/3 3. - 3/4 4. None of the above Which of the following statements is FALSE? 1. a. a/c + b/c = (a + b)/c 2. b. a/c - b/c = (a - b)/c 3. c. (a/c) ÷ (b/c) = a/b, (b ? 0) 4.d. None of the above If three-fifths of the students in a class are female and 12 students are male, then what...
NOTE:- PLEASE USE THE INSTRUCTION ACCORDING TO "CHAPTER 3" OF "STARTING OUT WITH PYTHON 4TH EDITION"...
NOTE:- PLEASE USE THE INSTRUCTION ACCORDING TO "CHAPTER 3" OF "STARTING OUT WITH PYTHON 4TH EDITION" PROGRAM 3_1:- Write a program that determines the cost of online order of T-shirts. T-shirts are priced at $12.99 each, but discounts are applied for quantities as follows: - 12 or more shirts earn a 30% discount and free shipping - 6-11 shirts earn a 20% discount - and 3-5 shirts earn a 10% discount - 1 or 2 shirts, no discounts Prompt the...
a/b x c/dy Let's design a class and explore more on object reference: A fraction with...
a/b x c/dy Let's design a class and explore more on object reference: A fraction with two private fields: a for representing numerator and b for representing denominator. Define a constructor Fraction() accept two integers to represent the numerator and denominator. Define a public instance method named printString() which returns a String in form of "a/b". Define a public instance method named multiplyBy() which accepts one argument of class type Fraction, calculates the multiplication between self and the receiving Fraction,...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...