Write a python program Write a program to help a user figure out the lowest pric
ID: 671831 • Letter: W
Question
Write a python program Write a program to help a user figure out the lowest price milk. Your program should ask the user to input prices of milk 5 times. It should then print the lowest price. Additionally, your program should print all the prices in decreasing order (highest to lowest). Then your program should print the average of the two middle prices, and the square root of the highest price. Finally your program should remove the most expensive price and print the remaining price again. HINT: start with an empty list and keep adding prices to it as the user enters them.Explanation / Answer
Program:
milk_price=[]
n=5
price=0.0;
i=0
avg=0.0
square_value=0.0
mid=0;
for i in range(n):
price=float(input('Enter milk price:'))
milk_price.append(price)
milk_price.sort()
print("lowest milk price:",milk_price[0])
milk_price.reverse()
print("Price array sorted in decreasing order")
print(milk_price)
mid=round(n/2)
avg=milk_price[mid]+milk_price[mid+1]
avg=avg/2
print("Average value of two middle elements");
print(avg)
square_value=milk_price[0]**(0.5)
print("square value of highest price");
print(square_value)
milk_price.remove(milk_price[0])
print("After removing highest price")
print(milk_price)
Output:
>>>
Enter milk price:34
Enter milk price:12
Enter milk price:89
Enter milk price:90.50
Enter milk price:72.75
lowest milk price: 12.0
Price array sorted in decreasing order
[90.5, 89.0, 72.75, 34.0, 12.0]
Average value of two middle elements
53.375
square value of highest price
9.513148795220223
After removing highest price
[89.0, 72.75, 34.0, 12.0]
>>>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.