GIAC GPYC Practice Questions with Explanations

Free GIAC GPYC practice questions. 10 of them, each with the correct answer, a full explanation, and the reason every other option is wrong.

GPYC practice questions

Question 1

A user enters unexpected data into program.

Which functionality can the programmer use to present an understandable error message to the user?

  • A. Casting
  • B. Exception handling
  • C. Dictionaries
  • D. Regular expressions
Show answer and explanation ▾

Correct answer: B

With try and except, the program catches the error that bad input raises (such as a ValueError) and prints a clear message instead of crashing with a traceback.

Why the other options are wrong:

  • A. Casting converts a value to another type, and bad input makes the cast itself fail; it does not produce a friendly message.
  • C. A dictionary stores key and value pairs; it has nothing to do with reporting input errors.
  • D. A regular expression can check the format of input, but on its own it does not catch errors or show messages.

Question 2

What is the output of the following line of code typed into a Python interactive session?

>>> print(bin(0b101010 ^0b111000))

  • A. 0b10101
  • B. 18
  • C. 0b10010
  • D. 0b101101
Show answer and explanation ▾

Correct answer: C

The ^ operator is bitwise XOR, which sets a bit only where the two inputs differ. 101010 XOR 111000 is 010010, and bin() shows it without the leading zero as 0b10010.

Why the other options are wrong:

  • A. 0b10101 is not the XOR of the two values.
  • B. 18 is the decimal value, but bin() returns a binary string with the 0b prefix.
  • D. 0b101101 is not the XOR of the two values.

Question 3

What happens if a programmer fails to build exception handling into a program, and the program encounters an unexpected error condition?

  • A. The interpreter will ignore the error and move to the next line.
  • B. The application will print a warning to the console and continue to the end
  • C. The computer will "fuzz" input until it finds one that generates no error
  • D. The application will terminate immediately or after resources are exhausted
Show answer and explanation ▾

Correct answer: D

An exception that no handler catches travels up the call stack and stops the program with a traceback. Without exception handling the program cannot recover, so it terminates.

Why the other options are wrong:

  • A. The interpreter does not skip a failing line and carry on.
  • B. An unhandled exception stops the program instead of printing a warning and continuing.
  • C. Python does not retry with different input when an error occurs.

Question 4

After calling a subprocess in a Python program, the program returns an error code of `0`.

What does this indicate?

  • A. The subprocess did not run
  • B. The subprocess terminated with no errors
  • C. The subprocess entered an infinite loop condition
  • D. The subprocess encountered a race condition
Show answer and explanation ▾

Correct answer: B

By convention a process exit status of 0 means success. A return code of 0 from a subprocess shows that it ran and finished without reporting an error.

Why the other options are wrong:

  • A. A return code is only available once the subprocess has run and exited.
  • C. A process in an infinite loop does not exit, so it returns no code.
  • D. A return code of 0 reports success, not a race condition.

Question 5

Which python regular expression method should be used to match any character in a-z, 0-9, or !@#$%^&*()?

  • A. \W
  • B. Greedy matching
  • C. A custom character set
  • D. \w
Show answer and explanation ▾

Correct answer: C

Square brackets define a custom set of characters, and the pattern matches any one character listed in it. A set that lists a-z, 0-9 and the required symbols matches exactly those characters, which no predefined class does.

Why the other options are wrong:

  • A. \W matches any character that is not a word character, so it does not match letters or digits.
  • B. Greedy matching describes how much text a quantifier consumes, not which characters match.
  • D. \w matches letters, digits and the underscore, so it does not match the listed symbols.

Question 6

Which of the following import statements will add the ability to parse data with regular expressions to your script?

  • A. from regex import re
  • B. import re
  • C. from re import regex
  • D. import regex
Show answer and explanation ▾

Correct answer: B

Regular expression support in the Python standard library lives in the re module. The statement import re makes functions such as re.search() and re.findall() available.

Why the other options are wrong:

  • A. The standard library has no regex module that contains re.
  • C. The re module does not provide a name called regex.
  • D. regex is not the standard library module for regular expressions.

Question 7

A log file is stored in variable `a`. The file has the following format for each log entry, in order, stored in big endian:

  • Field 1: 2-byte integer
  • Field 2: 2-byte integer
  • Field 3: 4-byte integer

Which of the following would unpack a line from the log file into the proper fields?

  • A. struct.unpack('>HH4s',a)
  • B. struct.unpack('<HHssss',a)
  • C. struct.unpack('>HHHH',a)
  • D. struct.unpack('!BxBx4s',a)
Show answer and explanation ▾

Correct answer: A

The > character selects big endian byte order. Each H reads a 2-byte unsigned integer and 4s reads the last four bytes as one field, giving three fields of 2, 2 and 4 bytes.

Why the other options are wrong:

  • B. The < character selects little endian byte order, and the data is big endian.
  • C. Four H codes split the data into four 2-byte fields instead of three fields.
  • D. B reads a single byte and x skips a byte, so the 2-byte integers are not read correctly.

Question 8

If the variable `example` contains a handle to a subprocess object, which of the following would show all of the possible results of running the subprocess?

  • A. example.stdout.read()
  • B. example.recv(*)
  • C. example.read()
  • D. example.stdout.read()+example.stderr.read()
Show answer and explanation ▾

Correct answer: C

A pipe handle such as the one os.popen() returns is an open file object connected to the child process. Calling read() on that handle returns everything the command wrote to the pipe, up to end of file.

Why the other options are wrong:

  • A. example.stdout.read() reads the standard output stream only, so error output is left out.
  • B. recv() is a socket method and is not how a subprocess handle is read.
  • D. Reading stdout and then stderr one after the other can deadlock when the other pipe buffer fills, which the subprocess documentation warns against.

Question 9

Which command will search for python modules that will have the ability to parse pcap files?

  • A. >>>locate(pcap)
  • B. pip search pcap
  • C. pip pcap
  • D. >>> pfind(pcap)
Show answer and explanation ▾

Correct answer: B

pip search is the pip subcommand that searches the Python Package Index for packages whose name or summary contains the query. Here the query is pcap.

Why the other options are wrong:

  • A. locate() is not a Python built-in for finding modules.
  • C. pip needs a subcommand such as search, and pcap is not one.
  • D. pfind() is not a Python built-in for finding modules.

Question 10

When creating a new socket using the Python `sockets` module, which of the following parameters is used to specify the socket will send and receive TCP traffic?

(Choose two)

  • A. socket.SOCK_STREAM
  • B. socket.AF_INET
  • C. socket.SOCK_DGRAM
  • D. socket.socket
Show answer and explanation ▾

Correct answer: A, B

A TCP socket is created with socket.AF_INET, which selects the IPv4 address family, and socket.SOCK_STREAM, which selects a connection-oriented stream socket. Together they produce a socket that sends and receives TCP traffic.

Why the other options are wrong:

  • C. socket.SOCK_DGRAM creates a datagram socket, which is UDP.
  • D. socket.socket is the function that creates the socket, not a parameter that selects TCP.

Get the complete GPYC bank

These 10 questions are roughly 14% of the bank. The full pack has 73 real exam questions, each with the same depth of explanation, plus a questions-only PDF for timed practice and free updates forever.

View the full GIAC GPYC question bank →

About the GPYC exam

These 10 GIAC GPYC questions are free here. The free sample PDF has 23.

Back to blog