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
C program fractions.c that does the following: 1. The program starts by making the user enter...
C program fractions.c that does the following: 1. The program starts by making the user enter a non-negative integer number a, called the first numerator. If the user enters a negative number, the program repeats the entry. 2. The program then makes the user enter a positive integer number b, called the first denominator. If the user enters a non-positive number, the program repeats the entry. 3. The program then makes the user enter a non-negative integer number c, called...
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...
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...
Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1,...
Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 }; Write a C++ program to ask the user to enter a number, if the number can be found in the array, your program should display "Found". Otherwise, your program should display "Not found". For example, if the user enters 7, your program should display "Found". If the user enters 11, your program should display "Not found".
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...
Problem Description Many recipes tend to be rather small, producing the fewest number of servings that...
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 that comes from...
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,...
(a) If you roll a single die and count the number of dots on top, what...
(a) If you roll a single die and count the number of dots on top, what is the sample space of all possible outcomes? Are the outcomes equally likely? 0, 1, 2, 3, 4, 5, 6; not equally likely 0, 1, 2, 3, 4, 5, 6; equally likely     1, 2, 3, 4, 5, 6; not equally likely 1, 2, 3, 4, 5, 6; equally likely (b) Assign probabilities to the outcomes of the sample space of part (a). (Enter your...
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...