Question 1
What is the output of the following code? import math print(math.floor(-3.5), math.trunc(-3.5), int(-3.5))
Show answer & explanation
Correct answer: A - -4 -3 -3
10 exam-style questions with answers and explanations, straight from our 1,030-question bank. Tap an answer to check yourself. When you're ready, take the scored version in the free practice test.
The PCAP exam has 40 questions and runs 1 hour 5 minutes.
These 10 free PCAP questions are organized by exam domain, so you can see how each part of the PCAP - Certified Associate in Python Programming blueprint is tested. Reveal the answer and explanation under each question.
What is the output of the following code? import math print(math.floor(-3.5), math.trunc(-3.5), int(-3.5))
Correct answer: A - -4 -3 -3
A developer writes the following two lines and runs them on a standard CPython 3 installation: import platform print(platform.python_version_tuple()[0] + 1) What is the result?
Correct answer: C - A TypeError, because the tuple contains strings, not integers
What happens when the following code is executed? try: print(1 / 0) except Exception: print('general') except ZeroDivisionError: print('specific')
Correct answer: B - general is printed
What is the output of the following code? def check(): try: return 'try' finally: return 'finally' print(check())
Correct answer: B - finally, because it replaces the value returned earlier
A script contains the following code. What appears on standard output? import sys try: sys.exit(1) except Exception: print('caught') print('done')
Correct answer: D - Nothing is printed; the script terminates immediately
What is the output of the following code? print('www.example.com'.strip('cmowz.'))
Correct answer: C - example
What is the output of the following code? print('a,,b,'.split(','))
Correct answer: D - ['a', '', 'b', '']
What is the output of the following code? print('Zebra' < 'apple', '10' < '9')
Correct answer: A - True True
What is the output of the following code? print('certification'[::-3])
Correct answer: B - ntitc
What is the output of the following code? class Snake: victims = 0 def __init__(self, name): self.name = name Snake.victims += 1 a = Snake('Ka') b = Snake('Nag') b.victims = 99 c = Snake('Hiss') print(Snake.victims, a.victims, b.victims)
Correct answer: C - 3 3 99
The PCAP exam also covers these domains. Drill them in the full free practice test:
The full bank has 1,020 more PCAP questions with explanations.
Continue in the free practice test →
View plans