Question 1
What is the output of the following code? print(~100)
Show answer & explanation
Correct answer: C - -101
10 exam-style questions with answers and explanations, straight from our 1,054-question bank. Tap an answer to check yourself. When you're ready, take the scored version in the free practice test.
The GPYC exam has 75 questions and runs 2 hours.
These 10 free GPYC questions are organized by exam domain, so you can see how each part of the GIAC Python Coder (GPYC) blueprint is tested. Reveal the answer and explanation under each question.
What is the output of the following code? print(~100)
Correct answer: C - -101
A script contains the line: age = input('Enter your age: ') The user types 42 and presses Enter. What is the data type of age?
Correct answer: B - str
What is the output of the following code? data = [10, 20, 30, 40, 50] print(data[1:4])
Correct answer: A - [20, 30, 40]
What is the output of the following code? print(b'\x48\x49'.decode())
Correct answer: D - HI
What does the following code print? for n in [1, 2, 3]: if n == 5: break else: print('done')
Correct answer: B - done
What is the output of the following code? def add(item, lst=[]): lst.append(item) return lst print(add(1)) print(add(2))
Correct answer: C - [1] then [1, 2]
What does the following code print? def greet(name): print('Hello ' + name) result = greet('Sam') print(result)
Correct answer: A - Hello Sam then None
What is the output of the following code? try: x = 10 / 2 except ZeroDivisionError: print('error') else: print('else') finally: print('finally')
Correct answer: D - else then finally
Which exception is raised by the following code? number = int('twelve')
Correct answer: B - ValueError
In Python's re module, which function attempts to match a pattern ONLY at the beginning of the string?
Correct answer: A - re.match()
The GPYC exam also covers these domains. Drill them in the full free practice test:
The full bank has 1,044 more GPYC questions with explanations.
Continue in the free practice test →
View plans