QuestionQ127

VerifiedControl Flow – Conditional Blocks and Loops

The ABC organics company requires a simple call-center program for entering survey data about a new coffee variety. The program must accept ratings on a five-star scale and return the average rating. Round the output to two decimal places.

Complete the code so that it meets these requirements.

What should be inserted in place of XXX, YYY, and ZZZ?

Drag & Drop
sum = count = done = 0
average = 0.0

while done != -1:
    rating = 
    if rating == -1:
        break
    sum += rating
    count += 1

average = float(sum / count)

 + 
Explanation

float(input(...)) reads each entered rating as a numeric value so it can be compared with the -1 sentinel and included in the calculation. format(average, '.2f') produces a fixed two-decimal representation. The print call supplies the required output label.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!