WGU D522 Python for IT Automation
OA Actual Exam 2026/2027 | Questions
with Verified Answers | 100% Correct |
Pass Guaranteed
Q001: You need to list all files with the extension
.log in /var/log and print their absolute paths. Which
snippet accomplishes this?
A. print(glob.glob('.log'))
B. print(glob.glob('/var/log/.log'))
C. print(os.listdir('/var/log'))
D. print(glob.glob('/var/log/*', recursive=True))
ANSWER: B
Q002: A script must read a JSON file config.json
and return the value associated with key "host".
Which code correctly loads the file and retrieves the
value?
A. with open('config.json') as f: return f.read()['host']
B. with open('config.json') as f: return
P a g e 1 | 29
, 2
json.load(f)['host']
C. return json.loads('config.json')['host']
D. with open('config.json','w') as f: return
json.dump(f)['host']
ANSWER: B
Q003: You want to append the string "DONE\n" to a
file tasks.txt. Which snippet performs this correctly?
A. open('tasks.txt','w').write("DONE\n")
B. with open('tasks.txt','a') as f: f.write("DONE\n")
C. open('tasks.txt','r').append("DONE\n")
D. with open('tasks.txt','x') as f: f.write("DONE\n")
ANSWER: B
Q004: A function receives a list of IP strings and
must return the first valid IPv4 address (regex
provided). Which implementation is correct?
A. return
re.search(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}′,ips)B.fo
ripinips:ifre.fullmatch(r′\d1,3\d˙1,3\d˙1,3\d˙1,3 ', ip):
return ip
C. return
re.findall(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}′,ips)[0]
P a g e 2 | 29
, 3
D.returnre.match(r′\d1,3\d˙1,3\d˙1,3\d˙1,3 ',
ips).group()
ANSWER: B
Q005: A script must create a backup copy of folder
/home/user/data to /home/user/data_backup. Which
shutil call accomplishes this?
A.
shutil.copy('/home/user/data','/home/user/data_backu
p')
B.
shutil.copytree('/home/user/data','/home/user/data_ba
ckup')
C.
shutil.move('/home/user/data','/home/user/data_back
up')
D.
os.rename('/home/user/data','/home/user/data_backu
p')
ANSWER: B
Q006: You need to run the shell command "df -h"
and capture its stdout. Which subprocess snippet is
P a g e 3 | 29