exam questions

Exam 98-381 All Questions

View all questions & answers for the 98-381 exam

Exam 98-381 topic 1 question 31 discussion

Actual exam question from Microsoft's 98-381
Question #: 31
Topic #: 1
[All 98-381 Questions]

HOTSPOT -
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.
How should you complete the code? To answer, select the appropriate code segments in the answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
References: https://www.w3resource.com/python/python-format.php#num

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
TusharK
3 years, 7 months ago
Can someone please correct the code below : 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'))
upvoted 1 times
Sarah987
2 years, 1 month ago
You used capital on 'Average'. It should be the lower case and your indentation is wrong. Here is the correct code; 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'))
upvoted 1 times
...
...
Daan_peacock
4 years, 1 month ago
Because it is numerical
upvoted 1 times
...
sagacious_smith
4 years, 2 months ago
the code is wrong. when float(input()) is used to accept the user input, how will it ever match as -1 ? it should be -1.0.
upvoted 3 times
Sarah987
2 years, 1 month ago
if rating == -1: works as it evaluates the value. If you check print(-1.0 == -1) it says True but print(rating is -1) is False.
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago