Question

You are learning fractions and you want to be able to obtain the maximum value in...

You are learning fractions and you want to be able to obtain the maximum value in a list of 3 fractions (floats). Write a function called maxFraction that receives a string containing 3 fractions separated by comma (input), and returns the maximum value.

Example Function Calls:

maxFraction(‘0.5,0.3,0.1’); should return “The max value is 0.5”

please help, language is python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE :

def maxFraction(string) :
list1 = list() # define one list
string1 = ""
for i in string:
if i != ',':
string1 = string1 + i
else :
list1.append(string1) # push the items to list by removing commas
string1 = ""
list1.append(string1)
a = list1[0] # store it in variables
b = list1[1]
c = list1[2]
if a > b: # compare each element to know the maximum
if a > c:
return a
else :
return c
elif b > c:
return b
return c
  

string = str(input()) # read the string
maximum = maxFraction(string) # pass the string as argument
print("The max value is ", maximum)
  

OUTPUT :

Add a comment
Know the answer?
Add Answer to:
You are learning fractions and you want to be able to obtain the maximum value in...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Comma Code (Using Python Language) Say you have a list value like this: spam = [...

    Comma Code (Using Python Language) Say you have a list value like this: spam = [ 'apples' , 'bananas' , 'tofu', 'cats' ] Write a function that takes a list value as an argument and returns a string will all the items separated by comma and space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu and cats'. but your function should be able to work with...

  • PYTHON 1- Write a function that receives a string value as a parameter, converts its first...

    PYTHON 1- Write a function that receives a string value as a parameter, converts its first character to uppercase and returns the first character. 2- Test your function by writing a main, which calls your function and prints its return value. 3- Save your program in a file called firstChar.py and use the following link to submit your file.  

  • Please write a function in C++ named nextString that will return a single 'value' (i.e. substring)...

    Please write a function in C++ named nextString that will return a single 'value' (i.e. substring) from a Comma Separated Value" string. Your function will take two arguments: a string variable containing a comma separated list of values, and an integer containing the starting index; your function should return a single string object with the value that starts at that index and ends right before the next comma ',' (do not include the comma in the returned string!) : string...

  • Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in te...

    Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in text container -- class str-- and lists containing multiple strings. One of the advantages of the str class is that, to the programmer, strings in your code may be treated in a manner that is similar to how numbers are treated. Just like ints, floats, a string object (i.e., variable) may be initialized with a literal value or the contents...

  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

  • Sample program run - Needs to be coded in python -Enter the text that you want to search for, Or DONE when finished: val...

    Sample program run - Needs to be coded in python -Enter the text that you want to search for, Or DONE when finished: valiant paris The valiant Paris seeks for his love. -Enter the text that you want to search for, or DONE when finished: Romeo and Juliet Enter Romeo and Juliet aloft, at the WIndow -- Enter the text that you want to search for, DONE when finished: DONE   # copy the following two lines into any # program...

  • Can you send the code and the screenshot of it running? 1) Create a PYHW2 document...

    Can you send the code and the screenshot of it running? 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both flowchart and pseudocode forms for the following two functions: A. Write a Python function that receives a real number argument representing the sales amount for videos rented so far this month The function asks the user for the number...

  • Find the local maximum and minimum values and saddle point(s) of the function. If you have...

    Find the local maximum and minimum values and saddle point(s) of the function. If you have three-dimensional graphing software, graph the function with a domain and viewpoint that reveal all the important aspects of the function. (Enter your answers as a comma-separated list. If an answer does not exist, enter DNE.) f(x,y) - 2x2 - 6x + 6xy2 local maximum value(s) local minimum value(s) saddle points) Need Help? Read it Talk to a Tutor Submit Answer (-/3 points) DETAILS SCALCET8...

  • IN PYTHON Develop the program that will allow you to obtain an ordered list of whole...

    IN PYTHON Develop the program that will allow you to obtain an ordered list of whole numbers from least to greatest from two lists of whole numbers. The individual values ​​of the input lists are captured by the user one by one and then both lists will be joined and then sorted in ascending order (from lowest to highest value). Your program should allow the capture of the entire values ​​of the lists without making use of messages (legends) to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT