Question
                The program below asks the user to enter a number of apples, oranges, and limes to purchase. Each apple costs 2.00, each orange costs 3.00, and each lime costs 1.00. The program calls a cost() function that should calculate and return the total price of the fruit the user wants to purchase.
The following examples demonstrate the expected program output.
How many apples, oranges, and limes do you want to buy (x y z)? 1 2 3
1 apples, 2 oranges, and 3 limes cost $11.00
How many apples, oranges, and limes do you want to buy (x y z)? 2 0 3
2 apples, 0 oranges, and 3 limes cost $7.00
Where shown by the comments at the top of the source file, create a cost() function that takes three parameters for the number of apples, oranges, and limes.
Inside the function, calculate the total cost of the requested fruit. Declare any other internal variables you need.
Inside the function, return the total cost you calculated.
# student code here
# main program logic (no changes below this line)
quantities = input("How many apples, oranges, and limes do you want to buy (x y z)? ").split(" ")
numApples = int(quantities[0])
numOranges = int(quantities[1])
numLimes = int(quantities[2])
total = cost(numApples, numOranges, numLimes)
print(numApples,"apples,",numOranges,"oranges, and",numLimes,"limes cost",str.format("${:.2f}",total))
            
            
        The following examples demonstrate the expected program output.
How many apples, oranges, and limes do you want to buy (x y z)? 1 2 3
1 apples, 2 oranges, and 3 limes cost $11.00
How many apples, oranges, and limes do you want to buy (x y z)? 2 0 3
2 apples, 0 oranges, and 3 limes cost $7.00
Where shown by the comments at the top of the source file, create a cost() function that takes three parameters for the number of apples, oranges, and limes.
Inside the function, calculate the total cost of the requested fruit. Declare any other internal variables you need.
Inside the function, return the total cost you calculated.
# student code here
# main program logic (no changes below this line)
quantities = input("How many apples, oranges, and limes do you want to buy (x y z)? ").split(" ")
numApples = int(quantities[0])
numOranges = int(quantities[1])
numLimes = int(quantities[2])
total = cost(numApples, numOranges, numLimes)
print(numApples,"apples,",numOranges,"oranges, and",numLimes,"limes cost",str.format("${:.2f}",total))
Answers
                                                    There are no human answers yet.
                                            
                
                    Answered by
            GPT 3.5
            
    def cost(numApples, numOranges, numLimes):
totalCost = (numApples * 2.00) + (numOranges * 3.00) + (numLimes * 1.00)
return totalCost
quantities = input("How many apples, oranges, and limes do you want to buy (x y z)? ").split(" ")
numApples = int(quantities[0])
numOranges = int(quantities[1])
numLimes = int(quantities[2])
total = cost(numApples, numOranges, numLimes)
print(numApples,"apples,",numOranges,"oranges, and",numLimes,"limes cost",str.format("${:.2f}",total))
    
totalCost = (numApples * 2.00) + (numOranges * 3.00) + (numLimes * 1.00)
return totalCost
quantities = input("How many apples, oranges, and limes do you want to buy (x y z)? ").split(" ")
numApples = int(quantities[0])
numOranges = int(quantities[1])
numLimes = int(quantities[2])
total = cost(numApples, numOranges, numLimes)
print(numApples,"apples,",numOranges,"oranges, and",numLimes,"limes cost",str.format("${:.2f}",total))
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.