🐍 Python Pa help po sa activity about loops

Problem:
Picture yourself as a barista experimenting with various coffee brewing methods. The program should prompt the user to input the number of methods they've tested. Following that, it should iteratively ask for the brewing time for each method. After all the times are inputted, the program ought to reveal the quickest, longest, and mean brewing durations.

Use either for or while loop.

Ito po nasimulan ko diko na alam next.

numOfMethods = int(input("Number of tested methods: "))

for n in range(numOfMethods):
n += 1
brewingTime = float(input(f"Time {n}: "))
 
Here's how you can complete the rest of the program using a for loop:

Python:
numOfMethods = int(input("Number of tested methods: "))

brewingTimes = []  # to store the brewing times

for n in range(numOfMethods):
    n += 1
    brewingTime = float(input(f"Time {n}: "))
    brewingTimes.append(brewingTime)  # add the brewing time to the list

# calculate the quickest, longest, and mean brewing durations
quickest = min(brewingTimes)
longest = max(brewingTimes)
mean = sum(brewingTimes) / numOfMethods

# display the results
print(f"Quickest brewing duration: {quickest}")
print(f"Longest brewing duration: {longest}")
print(f"Mean brewing duration: {mean}")

This code first creates an empty list called brewingTimes to store the brewing times for each method. Inside the loop, it prompts the user to input the brewing time for each method and adds it to the list using the append() function.

After the loop ends, it calculates the quickest, longest, and mean brewing durations by using the min(), max(), and sum() functions respectively.

Finally, it displays the results using the print() function.
 

About this Thread

  • 2
    Replies
  • 866
    Views
  • 2
    Participants
Last reply from:
jccarrera

Trending Topics

Online now

Members online
1,196
Guests online
1,884
Total visitors
3,080

Forum statistics

Threads
2,315,210
Posts
29,181,626
Members
1,183,459
Latest member
ivanismo
Back
Top