What should you insert instead of XXX, YYY and ZZZ?

The ABC organics company needs a simple program that their call center will use to enter survey data for a new coffee variety. The program must accept input and return the average rating based on a five-star scale.

The output must be rounded to two decimal places.

You need to complete the code to meet the requirements.

sum = count = done = 0

average = 0.0

while done != -1:

rating = XXX

if rating == -1:

break

sum += rating

count += 1

average = float(sum / count)

YYY + ZZZ

What should you insert instead of XXX, YYY and ZZZ?
A . XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2d’))
B. XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> printline(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2f’))
C. XXX -> print(input(‘Enter next rating (1-5), -1 for done’))
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2f’))
D. XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> output(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2d’))
E. XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2f’))
F. XXX -> input(‘Enter next rating (1-5), -1 for done’)
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2d’))

Answer: E

Explanation:

Topics: while not equal to operator if

add and assign operator float()

division operator format()

plus operator string concatenation

Try it yourself:

sum = count = done = 0

average = 0.0

while done != -1:

rating = float(input(‘Enter next rating (1-5), -1 for done’))

if rating == -1:

break

sum += rating

count += 1

average = float(sum / count)

print(‘The average star rating for the new coffee is: ‘ + format(average, ‘.2f’))

# format(average, ‘.2d’) -> ValueError: …

The input() function always returns a string

You need to cast that string to a float with the float() function.

The function to print something to the monitor is called print()

And if you want to round a float to two decimal places,

you need the format string ‘.2f’

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments