exam questions

Exam 98-381 All Questions

View all questions & answers for the 98-381 exam

Exam 98-381 topic 1 question 2 discussion

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

HOTSPOT -
You are coding a math utility by using Python.
You are writing a function to compute roots.
The function must meet the following requirements:

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:
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
YES1224
Highly Voted 4 years, 8 months ago
Answer is correct I have tested 1 = if a >= 0 : 2 = else: 3 = if a % 2 == 0: 4 = else:
upvoted 9 times
...
CERTIFICATION1990
Highly Voted 4 years, 9 months ago
The ans should be 1. if a>=0 2. if a%2 ==0 3. else
upvoted 6 times
...
TrevorSmit
Most Recent 2 years, 12 months ago
There must be more code hidden behind the dropdowns in the screenshot. I have made slight modifications to the code to make it work. You can change the parameters where the safe_root function is called to play with the outcomes. def safe_root(a, b): if a >= 0: answer = a ** (1 / b) return answer elif a % 2 != 0: answer = -(-a)**(1 / b) return answer else: answer = "3: Result is an imaginary number" return answer print(str(safe_root(2, 2))) def safe_root(a, b): if a >= 0: answer = a ** (1 / b) return answer elif a % 2 != 0: answer = -(-a)**(1 / b) return answer else: answer = "3: Result is an imaginary number" return answer print(str(safe_root(2, 2)))
upvoted 1 times
TrevorSmit
2 years, 12 months ago
Sorry pasted the code twice
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
...
allanmbs
4 years ago
Run the code: def safe_root(a, b): if a >= 0: answer = a**(1/b) elif a % 2 == 0: answer = "Result is an imaginary number" else: answer = -(-a)**(1/b) print(answer) safe_root(-1,4)
upvoted 2 times
...
gargaditya
4 years, 8 months ago
the answer is correct,only last else block needs another else to say answer=-(-a)**(1/b)
upvoted 1 times
...
pythonista
4 years, 10 months ago
i do not agree with the answer it should read if: elif: else:
upvoted 2 times
ProudlyIndian
4 years, 10 months ago
it should be else: If elif then condition should be with this statement like this - 'elif a%2 == 0' but that is not the option, we have the option only with 'if a%2 == 0' that will not work with elif
upvoted 2 times
Marcilla
4 years, 2 months ago
We don't have that answer because the question isn't written correctly. I agree with pythonista that the correct format is "if... elif... else"
upvoted 1 times
...
...
...
FuzzyDunlop
5 years ago
The answer looks correct
upvoted 2 times
FuzzyDunlop
4 years, 11 months ago
Actually, it looks like it's missing the last else statement to print the negative odd case
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 ...