1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aleksley [76]
3 years ago
15

Write a program that prompts the user to enter a fraction in the following format (x/y). You may assume that the user will input

numbers and a slash, but your program should deal with spaces. Use String methods to parse out the numerator and denominator (e.g. indexOf(), trim(), substring() etc.) Once you have the numerator and denominator, your program will determine whether the number is a proper fraction or an improper fraction. If it is a proper fraction, display the number. If not, reduce it to a mixed fraction or to an integer (see sample output below).
Computers and Technology
1 answer:
qaws [65]3 years ago
5 0

Answer:

fraction = input("enter fraction x/y: ")

if len(fraction) == 3:

   if fraction[1] == "/":

       try:

           num = int(fraction[0])

           den = int(fraction[2])

           if num < den:

               print(f"{num}/{den} is a proper fraction")

           else:

               if num% den == 0

                   print(f"{num}/{den} is an improper fraction and can be reduced to {num/den}")

               else:

                   print(f"{num}/{den} is an improper fraction and can be reduced to {num//den} + {num - (den * (num//den))}/{den}")

       except ValueError:

           print("numerator and denominator must be integer numbers")

Explanation:

The try and except statement of the python program is used to catch value error of the input fraction of values that are not number digits. The program converts the numerator and denominator string values to integers and checks for the larger value of both.

The program prints the fraction as a proper fraction if the numerator is lesser and improper if not.

You might be interested in
Who is this person?<br><br><br> Kaneppeleqw. I see them everywhere. Are they a bot? Are they human?
Effectus [21]
I’m not sure. Maybe a human.
6 0
3 years ago
What is the khan academy game where it is a block having to jump over lava and is an endless runner
saw5 [17]

Answer:https://www.khanacademy.org/computer-programming/lava-the-impossible-game-by-swax97/4638717300965376/embedded?id=1436456095000-0.5&origin=undefined&buttons=yes&embed=yes&editor=no&author=yes

Explanation:

5 0
4 years ago
When using a presentation software you can change the size of the text to...? Increase Font size, Decrease font size, increase t
ira [324]
Increase font size/ Decrease font size
7 0
3 years ago
Read 2 more answers
Select the correct answer.
miv72 [106K]

Answer: Format

Explanation: My head

3 0
3 years ago
Read 2 more answers
George has to present the goals of information management to his team member. What is a goal of information management? The goal
Law Incorporation [45]

Answer:

The purpose of information management is to: design, develop, manage, and use information with insight and innovation. support decision making and create value for individuals, organizations, communities, and societies.

Explanation:

5 0
3 years ago
Other questions:
  • Which statement is an example of an opinion from an online source?
    14·2 answers
  • Convert each of the following bit patterns into whole numbers. Assume the values are stored
    14·1 answer
  • What is the accounting equation?
    12·1 answer
  • Explain the purpose of the frame check sequence (fcs) field in a data link frame trailer.
    7·1 answer
  • Syah work as senior designer in creative design company. he is an imaginative person and always updates himself with the latest
    15·1 answer
  • How many words fit on a double-spaced page?
    11·1 answer
  • How many bits are required to store the text of the number "97" in ASCII?'
    5·2 answers
  • Cookies Are Us runs a series of 100 cookie stores across the Midwestern United States and central Canada. At the end of each day
    13·1 answer
  • Which of the following uses the proper syntax for creating an HTML comment?
    8·1 answer
  • Why does the use of passwords put the overall security of the network in jeopardy?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!