exam questions

Exam 98-381 All Questions

View all questions & answers for the 98-381 exam

Exam 98-381 topic 1 question 1 discussion

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

HOTSPOT -
You are writing a Python program to validate employee numbers.
The employee number must have the format ddd-dd-dddd and consist only of numbers and dashes. The program must print True if the format is correct and print if the format is incorrect.

False -
How should you complete the code? To answer, select the appropriate code segments in the answer area.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:

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
gargaditya
Highly Voted 4 years, 9 months ago
Incorrect first option,should initialize employee number as non blank value,otherwise how will the code ever enter the while loop (condition for entering is non blank value) to take the input. Also,the whole logic is to keep taking input when blank value is entered.
upvoted 10 times
...
TrevorSmit
Most Recent 3 years ago
I suspect that employee_number = "sentinel" is hidden behind the last dropdown screenshot. The below code works. employee_number = "" parts = "" while employee_number != "sentinel": valid = False employee_number = input("Enter employee number (ddd-dd-dddd): ") parts = employee_number.split('-') if len(parts) == 3: if len(parts[0]) == 3 and len(parts[1]) == 2 and len(parts[2]) == 4: if parts[0].isdigit() and parts[1].isdigit() and parts[2].isdigit(): valid = True employee_number = "sentinel" print(valid)
upvoted 1 times
...
Omkarrokee
3 years, 2 months ago
This would work with employee_number = "" and while employee_number != "sentinel": employee_number = "" parts = "" while employee_number != "sentinel": valid = False employee_number = input("Enter employee number (ddd-dd-dddd):- ") parts = employee_number.split('-') if len(parts) == 3: if len(parts[0]) == 3 and len(parts[1]) == 2 and len(parts[2]) == 4: if parts[0].isdigit() and parts[1].isdigit() and parts[2].isdigit(): valid = True print(valid) break else: valid = False print(valid) else: valid = False print(valid) else: valid = False print(valid)
upvoted 1 times
...
TheStudentOfPython
3 years, 4 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
...
PavanKumpatlaAccountTwo
3 years, 6 months ago
So this is my code: employee_number = "sentinel" parts = "" while employee_number != "": valid = False employee_number = input("Enter employee number (ddd-dd-dddd):- ") parts = employee_number.split('-') if len(parts) == 3: if len(parts[0]) == 3 and len(parts[1]) == 2 and len(parts[2]) == 4: if parts[0].isdigit() and parts[1].isdigit() and parts[2].isdigit(): valid = True print(valid) break else: valid = False print(valid) else: valid = False print(valid) else: valid = False print(valid)
upvoted 2 times
...
Amalanathan
3 years, 7 months ago
I think the first answer should be Employee_number = “” and the second answer as while employee_number != “sentinel”: because in programming, sentinel is the value that terminates a while loop so the second answer should be employee_number != “sentinel”: so if the user enters sentinel, it will terminate the while loop. Since the second answer is employee_number != “sentinel”: the first answer should be Employee_number = “” in order to run
upvoted 1 times
...
sudarchary
3 years, 9 months ago
Answer is correct: employee_number = "" parts = "" while employee_number != "": valid = False employee_number = input("Enter employee number (ddd-dd-dddd)") parts = employee_number.split('-') if len(parts) == 3: if len(parts[0]) == 3 and len(parts[1]) == 2 and len(parts[2]) == 4: if parts[0].isdigit() and parts[1].isdigit() and parts[2].isdigit(): valid = True print(valid) else: valid = False print(valid) else: valid = False print(valid) else: valid = False print(valid)
upvoted 2 times
...
warlospp
4 years, 1 month ago
#test this code employee_number = "sentinel" parts = "" while employee_number != "": valid = False employee_number = input("Enter employee number (ddd-dd-dddd)") parts = employee_number.split('-') if len(parts) == 3: if len(parts[0]) == 3 and len(parts[1]) == 2 and len(parts[2]) == 4: if parts[0].isdigit() and parts[1].isdigit() and parts[2].isdigit(): valid = True print(valid)
upvoted 1 times
...
allanmbs
4 years, 1 month ago
Run the code: employee_number = "" parts = "" while employee_number == "": valid = False employee_number = input("Enter employee number (ddd-dd-dddd)") parts = employee_number.split('-') if len(parts) == 3: if len(parts[0]) == 3 and len(parts[1]) == 2 and len(parts[2]) == 4: if parts[0].isdigit() and parts[1].isdigit() and parts[2].isdigit(): print(valid)
upvoted 2 times
...
Marcilla
4 years, 3 months ago
There are two typos. The case on the "E" in the first "employee_number" is a typo - it should be lower case. The condition to enter the while loop should be "==" rather than "!="
upvoted 2 times
...
ballooonparade
4 years, 6 months ago
this entire question doesnt make sense. Python is case sensitive so Employee_number is different from employee_number. so when it gets to while(employee_number != x) employee_number isnt a defined variable and the program will crash
upvoted 3 times
...
ra_de
4 years, 8 months ago
Is that answer correct
upvoted 1 times
...
nowisthetime
4 years, 12 months ago
It's correct. You are setting variables. It is checking to make sure Employee_Number is empty.
upvoted 1 times
...
FuzzyDunlop
5 years, 1 month ago
I don't understand the purpose of the while loop... The answer also seems incorrect because if you have while Employee_Number != "" right after you set Employee_Number to "", that code won't execute to initialize valid to false.
upvoted 3 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 ...