WGU Foundations of Programming (Python) - E010 JIV1 - Foundations-of-Programming-Python Free Exam Questions

QUESTION NO: 1
Complete the function get_dict_keys(data) that takes a dictionary and returns a list of all its keys.
For example, get_dict_keys({ " name " : " John " , " age " : 25}) should return [ " name " , " age " ].
def get_dict_keys(data):
# TODO: Return a list of all dictionary keys
pass
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: A dictionary stores data as key-value pairs.
Step 2: The .keys() method returns the dictionary's keys.
Step 3: To return the keys as a list, use list(data.keys()).
Correct code:
def get_dict_keys(data):
return list(data.keys())
Example:
print(get_dict_keys({ " name " : " John " , " age " : 25}))
Output:
[ ' name ' , ' age ' ]
QUESTION NO: 2
In the code for item in my_list:, what does item represent?

Correct Answer: D Vote an answer
Explanation: Only visible for Actual4test members. You can sign-up / login (it's free).
QUESTION NO: 3
Write a complete function word_count(text) that counts and returns the number of words in the given text.
Words are separated by spaces.
For example, word_count( " Hello world Python " ) should return 3.
def word_count(text):
# TODO: Count and return the number of words in text
pass
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The function receives one string parameter named text.
Step 2: Since words are separated by spaces, use the .split() method to split the string into a list of words.
Step 3: Use len() to count how many items are in the list.
Step 4: Return that count.
Correct code:
def word_count(text):
return len(text.split())
Example:
print(word_count( " Hello world Python " ))
Output:
3
QUESTION NO: 4
Which components are required in every Python for loop?

Correct Answer: C Vote an answer
Explanation: Only visible for Actual4test members. You can sign-up / login (it's free).
QUESTION NO: 5
Fix the indentation error in this function that should return a greeting message.
def greet(name):
return " Hello " + name
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: In Python, the code inside a function must be indented.
Step 2: The return statement belongs inside the function body.
Step 3: Add indentation before the return statement.
Correct code:
def greet(name):
return " Hello " + name
Example:
print(greet( " Alice " ))
Output:
Hello Alice
QUESTION NO: 6
Fix the missing return statement in this function that should return whether a number is even.
def is_even(number):
if number % 2 == 0:
True
else:
False
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The expression number % 2 == 0 checks whether the number is even.
Step 2: The original code writes True and False, but it does not return them.
Step 3: A function must use the return statement to send a value back to the caller.
Correct code:
def is_even(number):
if number % 2 == 0:
return True
else:
return False
Simplified correct code:
def is_even(number):
return number % 2 == 0
Example:
print(is_even(4))
print(is_even(7))
Output:
True
False
QUESTION NO: 7
Complete the function format_name(first, last) that takes a first name and last name and returns them combined as " last, first " .
For example, format_name( " John " , " Smith " ) should return " Smith, John " .
def format_name(first, last):
# TODO: Return the name in " last, first " format
pass
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The function receives two string parameters: first and last.
Step 2: The required format is the last name first, followed by a comma, a space, and then the first name.
Step 3: Use string concatenation to combine the values correctly.
Correct code:
def format_name(first, last):
return last + " , " + first
Example:
print(format_name( " John " , " Smith " ))
Output:
Smith, John

QUALITY AND VALUE

Actual4test Practice Exams are written to the highest standards of technical accuracy, using only certified subject matter experts and published authors for development - no all study materials.

Tested and Approved

We are committed to the process of vendor and third party approvals. We believe professionals and executives alike deserve the confidence of quality coverage these authorizations provide.

Easy to Pass

If you prepare for the exams using our Actual4test testing engine, It is easy to succeed for all certifications in the first attempt. You don't have to deal with all dumps or any free torrent / rapidshare all stuff.

Try Before Buy

Actual4test offers free demo of each product. You can check out the interface, question quality and usability of our practice exams before you decide to buy.