If num is not a number then the method will throw out exception then the answer will be 100, for example putting a character "a" in to method - magic("a")
But the main() method has statically defined the num as 5 - magic(5), which will never throw out an exception. answer should always be num + 2 * 10, which is 25 in this program
So the answer is C
The except block is used for error handling. In this scenario, if an error occurs during the execution of the try block—such as when a string is passed as an argument to the magic function—the except block will execute. In this case, the variable answer will be assigned a value of 100, which will then be returned.
def main():
print("The answer is " + str(magic("hi")))
def magic(num):
try:
answer = num + 2 * 10
except:
answer = 100
return answer
main()
Output:
The answer is 100
=== Code Execution Successful ===
https://www.programiz.com/python-programming/online-compiler/
Since '5' is a valid input to the "magic" function the answer is (5 + 2 * 10 = 25)
Output:
The answer is 25
=== Code Execution Successful ===
- I do see what your saying -
I tend to see and use input() as variables for change and anything else that in not for input is hard coded and not adjusted or seen by the user.
The print statement - yes, the value is converted to a string.
You can NOT add str() + int(), so it's just reverting the value back to string for a full print() statement.
upvoted 1 times
...
...
...
...
This section is not available anymore. Please use the main Exam Page.350-401 Exam Questions
Log in to ExamTopics
Sign in:
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.
kmb192006
Highly Voted 2 years agoLeoveil
1 year, 10 months agoAbdullahMohammad251
Most Recent 7 months ago[Removed]
11 months, 1 week ago[Removed]
11 months, 3 weeks agoslacker_at_work
1 year, 2 months agocwauch
1 year, 3 months agoTadese
1 year, 4 months agoEntivo
1 year, 10 months agonet_eng10021
1 year, 11 months agonet_eng10021
1 year, 11 months agoFarida_Fathi
2 years agoRman0059
2 years, 1 month agoRayZheng
2 years, 1 month agoNickplayany
2 years, 2 months agomakarov_vg
2 years, 2 months agoXDR
2 years agoSymirnian
2 years, 2 months agoXDR
2 years agoRickAO76
1 year agoRickAO76
1 year agoRickAO76
1 year ago