













































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
WGU D522 Python Programming Exam – 2026-2027 is a fully updated, comprehensive study resource designed for students preparing for the WGU D522 Python Programming Exam. This guide includes 300 actual exam-style questions with verified answers, aligned with current WGU course competencies and Python programming standards. Coverage includes Python syntax and semantics, data types and structures, control flow, functions, modules and packages, object-oriented programming, file handling, error handling, and practical coding applications. Each question is paired with a verified solution to reinforce understanding, improve coding skills, and build confidence for exam success. Ideal for WGU students, IT majors, and exam candidates seeking structured programming preparation, this resource ensures thorough practice, complete content review, and confident performance on exam day.
Typology: Exams
1 / 53
This page cannot be seen from the preview
Don't miss anything!














































Official Exam Overview: The WGU D522 Python Programming exam evaluates learners’ understanding of Python programming concepts, including data types, control structures, functions, object-oriented programming, file handling, and debugging. The exam emphasizes practical coding skills and problem-solving using Python. Exam Coverage Areas:
Rationale: Lists in Python are created using square brackets [ ]. Curly braces { } create sets or dictionaries, parentheses ( ) create tuples, and quotes create strings. QUESTION 3: What is the output of the following code? x = 5 y = 2 print(x ** y) A) 25 ✅ B) 10 C) 7 D) 3 Rationale: The ** operator in Python raises a number to the power of another. 5 ** 2 equals 25. QUESTION 4: Which keyword is used to define a function in Python? A) func B) define C) def ✅ D) function Rationale: The def keyword is used to define a function in Python. For example: def my_function(): print("Hello") QUESTION 5: Which data structure allows you to store key-value pairs in Python? A) list B) tuple C) dictionary ✅ D) set Rationale: Dictionaries in Python store data as key-value pairs using curly braces {}. For example: my_dict = {"name": "Alice", "age": 25 } What built-in data type is used when you assign text to your variable?
x = list(("apple", "banana", "cherry")) tuple x = ("apple", "banana", "cherry") x = tuple(("apple", "banana", "cherry")) range x = range(6) What is the difference between a list and a tuple? list = collection of values tuple = ordered and unchangeable What built-in data type is used when you assign a mapping to your variable? dict x = {"name" : "John", "age" : 36} x = dict(name="John", age=36) What built-in data type is used when you assign a set to your variable? set x = {"apple", "banana", "cherry"} x = set(("apple", "banana", "cherry")) frozenset x = frozenset({"apple", "banana", "cherry"}) x = frozenset(("apple", "banana", "cherry")) What built-in data type is used when you assign a boolean to your variable?
bool x = True x = bool(5) What built-in data type is used when you assign binary to your variable? bytes x = b"Hello" x = bytes(5) bytearray x = bytearray(5) memoryview x = memoryview(bytes(5)) What built-in data type is used when you assign the value none to your variable? nonetype x = none print(10 > 9) print(10 == 9) print (10 < 9) Boolean print(bool("Hello")) print(bool("15")) print(bool(x))
comma will print both items with a space between them print(variable) prints the value of the variable print("1\n2\n3") print using newline characters print( ) print a blank line python file.py run a script file random function there is no random function, but there is a random module (import random) for x in "bananas": print(x) strings are arrays, so this will loop through the characters in "bananas" variable=input( ) assign text entered by the user to a variable; input is always a string variable = int(input) convert user input into an integer
hourly_wage = int(input("Enter hourly wage: ")) display text prompt (Enter hourly wage) to request input from user and convert to integer print(a.upper( )) display a in console in upper case print(a.lower( )) display a in console as lower case print(a.strip( )) remove whitespace at beginning and end print(a.replace("H", "J")) replace a string with another string print(a.split("b")) split string at specified character c=a+b print(c) concatenate (combine) two strings a=(f"My name is John, I am {age}") print(a) f-string; { } is the placeholder/modifier
import sys print(sys.version) How do you edit, save, and run a Python file? edit = can edit in a text editor save = save as file.py run = in command prompt, type file.py Can you run Python in the Command Line? type python or py you will see Python version information and >>> when you are finished, type exit( ) What is unique about Python script formatting? relies on indentation (whitespace) to define scope instead of curly brackets Which Python datatypes are used to store arrays? list, tuple, set, and dictionary Which Python datatypes allow arrays with duplicates? list and tuple Which Python datatypes are for ordered arrays? list, tuple, dictionary Which Python datatypes are unchangeable? tuple and set
What kind of variable would x = [ ] result in? list How do you determine how many items are in a list? print(len(yourlist)) What are some characteristics of a list? ordered; changeable; allows duplicate values; new values added to the end of the list; indexed (first value if 0, second value is 1, etc.); values can be any datatype (and a mix of datatypes) What are some characteristics of a tuple? ordered; unchangeable; allows duplicate values What are some characteristics of a set? unordered; unchangeable (you can add or remove items, but you cannot change an item); unindexed What are some characteristics of a dictationary? ordered; changeable; no duplicates How do you verify the type of an object? print(type(myobject)) What is an integer? positive or negative whole number of unlimited length What is a float?
used to assign values to variables if x = 5 what is x += 3 8 if x = 5 what is x - = 2 3 *if x = 5 what is x = 3 15 if x = 5 what is x /= 3
if x = 5 what is x %= 3 2 if x = 5 what is x //= 3 1, which is assigned back to x **if x = 5 what is x = 3
125, which is assigned back to x What does == mean? equal to What does != mean? not equal to What are the comparison operators? == !=
<
= <= What are the logical operators? and, or, not What are the identity operators? is, is not What are the membership operators? in, not in What are the assignment operators?
bitwise operator OR compare bits and set each bit to 1 if at least one bit is 1 6 (0000000000000110) 3 (0000000000000011) 7 (0000000000000111) print(6 ^ 3) bitwise operator XOR compare bits and set each bit to 1 if only one bit is 1 6 (0000000000000110) 3 (0000000000000011) 5 (0000000000000101) print(~ 3) bitwise operator NOT inverts all the bits 3 (0000000000000011)
print(8 >> 2) bitwise operator signed right shift shifts right by pushing copies of the leftmost bit in from the left and letting the rightmost bits fall off 8 (0000000000001000) 2 (0000000000000010) What is operator precedence? parentheses exponentiation ** unary - (the negative value of the operand) multiplication, division, modulus % addition and subtraction left-to-right What is an f-string? allows you to format selected parts of a string; replaced format( ); specified by putting f in front of the string literal e.g. txt = f"The price is 49 dollars" How do you denote a placeholder in an f-string?
:< left :> right :^ center What modifiers are used to set thousand separators? :, comma :_ underscore Which modifiers are used to show a value's positive or negative sign? := shows negative sign in the left most position :+ shows sign for positive and negative numbers :- shows sign for negative number only :(space) shows sign for negative and an extra space for a positive number What is the modifier to show the value in binary format? :b What is the modifier to show the value in the corresponding Unicode character? :c What is the modifier to show the value in decimal format? :d What is the modifier to show the value in scientific format? :e :E for uppercase E What is the modifier to show the value in fix point number format?
if number not specified, shows 6 digits after decimal :f show inf and nan lowercase :F show inf and nan uppercase What is the modifier to show the value in general format? :g :G for uppercase E in scientific notation What is the modifier to show the value in octal format? :o What is the modifier to show the value in hex format? :x lowercase :X uppercase What is the modifier to show the value in number format? :n What is the modifier to show the value in percentage format? If number not specified, will show 6 numbers after decimal; can also use 0 for no decimal :% What characters are allowed in an identifier or name? letters, underscore, and digits What characters are allowed at the beginning of an identifier or name? must start with an underscore or a letter