Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam PCAP topic 1 question 61 discussion

Actual exam question from Python Institute's PCAP
Question #: 61
Topic #: 1
[All PCAP Questions]

What is the expected output of the following code?

  • A. 21
  • B. 12
  • C. 3
  • D. none
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
alopezme
1 month ago
There is no need for an else, if n != 1 it will return the n + f (n-1) So correct answer is 3
upvoted 1 times
...
blaze056
3 months, 3 weeks ago
Selected Answer: C
executed and verified
upvoted 1 times
...
TheFivePips
4 months, 3 weeks ago
Another example of where blind copy and paste makes this questions boarderline unanswerable.
upvoted 3 times
...
swyyuen
6 months, 1 week ago
def f(n): if n == 1: return 1 return n + f(n-1) print(f(2)) Answer will be 3 ------------------------------------ def f(n): if n == 1: return 1 return n + f(n-1) Answer will be None
upvoted 1 times
...
emanuelcar990
8 months, 1 week ago
The answer is None def f(n): if n == 1: return 1 return n + f(n-1) print(f(2)) test the code and result = None because dont have Else: on if
upvoted 1 times
...
owenmagas
8 months, 3 weeks ago
The answer to the problem is 3
upvoted 1 times
...
CC_DC
9 months, 2 weeks ago
Throw that code as-is and what are the results? D is the correct answer.
upvoted 2 times
...
Ello2023
10 months ago
Selected Answer: D
This is the correct code that prints 3 as the answers def f (n): if n == 1: return 1 else: return n + f (n-1) print (f(2))
upvoted 2 times
...
Ello2023
10 months ago
Selected Answer: D
D is correct
upvoted 1 times
...
Ello2023
10 months ago
when you run this snippet on a compiler it prints out None. Even if the indentation is corrected you can not have 2 results in one function unless it is separated by an else like below def get_absolute_value(num): if num < 0: return -num else: return num result = get_absolute_value(-5) print(result) # Output: 5
upvoted 1 times
...
david0001
1 year, 2 months ago
It's a recursive function that adds up all the numbers from n, n-1, n-2 ,...,1. So, given n=2, and assuming the indentation is correct, the result will be: 2 + 1 = 3.
upvoted 1 times
...
rotimislaw
1 year, 5 months ago
Selected Answer: C
C assuming the indentation is correct (there's no option for "the code causes runtime error", so I guess the indentation is correct)
upvoted 3 times
...
Ram5678
1 year, 6 months ago
The answer is C if the indentation is assumed to be correct.
upvoted 2 times
...
JO5H
1 year, 7 months ago
Selected Answer: C
Its not properly indented so it should return errors but since that is not an option then the answer is C if indentation is assumed to be correct
upvoted 2 times
...
alfonsocav1982
1 year, 8 months ago
The answer in this case is None as there is no "else" specified, so that works only when n==1
upvoted 1 times
...
Jnanada
1 year, 8 months ago
answer should be C if identation is correct
upvoted 1 times
...
MarkBell
1 year, 11 months ago
error based on indentation??
upvoted 1 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 ...