exam questions

Exam 98-381 All Questions

View all questions & answers for the 98-381 exam

Exam 98-381 topic 1 question 3 discussion

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

HOTSPOT -
You work for a company that distributes media for all ages.
You are writing a function that assigns a rating based on a user's age. The function must meet the following requirements:
✑ Anyone 18 years old or older receives a rating of "A"
✑ Anyone 13 or older, but younger than 18, receives a rating of "T"
✑ Anyone 12 years old or younger receives a rating of "C"
✑ If the age is unknown, the rating is set to "C"
You need to complete the code to meet the requirements.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
References: https://www.w3resource.com/python/python-if-else-statements.php

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
FuzzyDunlop
Highly Voted 4 years, 11 months ago
The answer is incorrect, here's what it should be: 1) age == None: rating = "C" 2) age < 13: rating = "C" 3) age < 18: rating = "T" 4) : rating = "A"
upvoted 30 times
nowisthetime
4 years, 10 months ago
All valid: 1) age == None: rating = "C" 2) age < 13: rating = "C" 3) age < 18: rating = "T" 4) : rating = "A" --- 1) age < 13: rating = "C" 2) age == None: rating = "C" 3) age < 18: rating = "T" 4) : rating = "A" ---- 1) age < 13: rating = "C" 2) age < 18: rating = "T" 3) age == None: rating = "C" 4) : rating = "A"
upvoted 7 times
Shivnath
4 years, 8 months ago
age <13: rating = "C" ---> this will throw error if age is None. so this cant be the first statement. need to check about "None" condition first.
upvoted 3 times
gargaditya
4 years, 8 months ago
Great observation Shivnath,we need to check None condition first to avoid errors in the scenario when None is passed in summary only single answer is correct: 1) age == None: rating = "C" 2) age < 13: rating = "C" 3) age < 18: rating = "T" 4) : rating = "A"
upvoted 7 times
...
...
...
...
JeffJupiter
Highly Voted 5 years ago
OR, first check if age==none elif age<13... elif age < 18... else #age must be above 18
upvoted 7 times
...
PriyaSwaminarayan
Most Recent 3 years, 1 month ago
Answer is not correct. Correct Code: def get_rating(age): rating = "" if age == None: rating = "C" elif (age < 13): rating = "C" elif age < 18: rating = "T" else: rating = "A"
upvoted 1 times
...
TheStudentOfPython
3 years, 3 months ago
So heres my code, if your_momWeight == 69420: print("Your mom is absolutely messed up my guy, you gotta get that checked out.")
upvoted 1 times
...
Kgotatso5050
3 years, 5 months ago
I've looked through the comment section regarding the ways in which the requirements can be fullfilled, is there a reason why there is a heirarchy, why would you have age < 18: rating = "T" first rather than having age < 13: rating = "C"
upvoted 1 times
...
sudarchary
3 years, 8 months ago
Incorrect: aa="" def get_rating(age): rating = "" if age == None: rating ="C" elif age<13: rating ="C" elif age < 18: rating ="T" else: rating = "A" return rating aa = get_rating(19) print(aa)
upvoted 1 times
...
rikku33
3 years, 9 months ago
def get_rating(age): rating = "" if age==None: rating ="C" elif age<13: rating ="C" elif age<18: rating ="T" else: rating = "A" return rating def get_rating1(age): rating = "" if age<18: rating ="T" elif age<13: rating ="C" elif age == None: rating ="C" else: rating = "A" return rating print(get_rating(None)) #print(get_rating1(None))
upvoted 1 times
...
warlospp
4 years ago
This is the correct answer def get_ratting(age): if age == None: rating = "C" elif age < 13: rating = "C" elif age < 18: rating = "T" else: rating = "A" return rating print(get_ratting(12))
upvoted 2 times
...
sadako11
4 years, 6 months ago
age == None MUST be the first condition tested to avoid error. right order: age == None: rating = "C" age < 13: rating = "C" age < 18: rating = "T" : rating = "A"
upvoted 1 times
...
PHULU
4 years, 7 months ago
this is a correct answer I have tested it 1) age < 13: rating = "C" 2) age < 18: rating = "T" 3) age == None: rating = "C" 4) : rating = "A"
upvoted 3 times
...
YES1224
4 years, 8 months ago
The first 2 values should be switched and it will give you the desired outcome I have tested. To be noted if an unknown value is entered it will give an error.
upvoted 3 times
...
maps7
4 years, 12 months ago
first 2 code should be switched coz if u start with 18 then if someone enters integer 12 they will get a T rating while anyone under 13 must get C rating.
upvoted 3 times
...
chandras
5 years, 2 months ago
yup..first 2 condns should be switched else it gives wrong classification for age <13.
upvoted 4 times
...
mecham
5 years, 2 months ago
I think this is wrong? the first 2 should be switched.
upvoted 5 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 ...