Exam 350-401 All QuestionsBrowse all questions from this exam
Question 736

Refer to the exhibit.

What is displayed when the code is run?

    Correct Answer: C

    The code first defines a main function that prints the result of calling the magic function with the argument 5. Inside the magic function, it attempts to execute the expression num + 2 * 10 without any potential exceptions. Since num is 5, the expression evaluates to 5 + 20, resulting in 25. Thus, the displayed output when the code is run is 'The answer is 25'.

Discussion
kmb192006Option: C

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

Leoveil

good explanation thanks

TadeseOption: C

def main(): print("The answer is" +str(magic(5))) def magic(num): try: answer=num+2*10 except: answer=100 return answer main() Output is 25

cwauchOption: C

Just use PEMDAS people. Answer is 25

NickplayanyOption: C

answer = num + 2 * 10 5 + 20

EntivoOption: C

It is C - I just tried it at programiz.com It adds the number (in this case, 5) to the calculated value of 2*10 (which is 20), hence 25.

Farida_FathiOption: C

Selected Answer: C

Rman0059Option: C

choose C

RayZhengOption: C

The answer should be C

makarov_vgOption: C

Answer C https://www.programiz.com/python-programming/online-compiler/ def main(): print (str(magic(5))) def magic(num): try: answer = num + 2 * 10 except: answer = 100 return answer main()

XDR

Yes. The input could be a string.

SeMo0o0oOption: C

C is correct num is 5, so answer = 5 + 2*10 = 25

SeMo0o0oOption: C

C is correct

slacker_at_workOption: C

Inside the magic() function, it tries to perform the operation num + 2 * 10. In this case, num is 5, so answer = 5 + 2 * 10, resulting in answer = 25.

net_eng10021Option: C

C def main(): print(str(magic(5))) def magic(num): try: answer = num+2*10 except: answer = 100 return answer main()

net_eng10021

Ran the above code and it does return 25

SymirnianOption: C

Answer is 25, why is there an exception here otherwise?

XDR

Yes. The input could be a string.

RickAO76

Input is hard-coded as an integer, 5. How can it be a string ? string = "5", or str(5) Integer = 5

RickAO76

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.

RickAO76

- 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.