These WGU Foundations of Programming (Python) (E010) sample questions are a small glimpse of our full set of WGU Foundations of Programming (Python) (E010) actual questions. They give you a preview of what the real Foundations of Programming (Python) (E010) exam might look like and the contents of Pass4Future's premium WGU Foundations of Programming (Python) (E010) product. You must not underestimate the value of WGU Foundations of Programming (Python) (E010) practice exam questions, as they allow you to understand the actual Foundations of Programming (Python) exam in greater depth. Using them will save your time and money otherwise wasted in Foundations of Programming (Python) exam reattempts. Study guides and tutorials provide you with theoretical details about the Foundations of Programming (Python) (E010) exam; these Foundations of Programming (Python) (E010) practice exam questions prepare you to pass the exam. Get Pass4Future's premium access to continue your Foundations of Programming (Python) (E010) exam practice with the complete set of WGU Foundations of Programming (Python) (E010) realistic questions. Our WGU Foundations of Programming (Python) (E010) practice questions come in various formats; make sure to check out the details and free demo of each format.
Do you know that you can access more real WGU Foundations-of-Programming-Python exam questions via Premium Access? ()
Which for loop correctly iterates through a list of student names?
Answer : A
The correct Python for loop syntax uses the keyword in.
Correct code:
for name in ['Alice', 'Bob', 'Carol']:
print(name)
This loop processes each name in the list one at a time. Python's documentation explains that a for statement iterates over the items of a sequence or iterable.
Therefore, the correct answer isA. for name in ['Alice', 'Bob', 'Carol']:.
Which keyword is used to exit a loop prematurely in Python?
Answer : B
The break keyword exits a loop immediately before the loop condition naturally becomes false or before all items have been processed.
Example:
for number in range(10):
if number == 5:
break
print(number)
When number becomes 5, the loop stops. Python's control-flow documentation explains the use of break in loops.
Therefore, the correct answer isB. break.
SIMULATION
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
Answer : A
==========
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
SIMULATION
Fix the indexing error in this function that should return the last character of a string.
def get_last_character(text):
return text[len(text)]
Answer : A
==========
Step 1: Python string indexing starts at 0.
Step 2: The last valid index of a string is len(text) - 1, not len(text).
Step 3: Python also allows negative indexing, where -1 means the last character.
Step 4: Replace text[len(text)] with text[-1].
Correct code:
def get_last_character(text):
return text[-1]
Example:
print(get_last_character('Python'))
Output:
n
Which Python data structure cannot be modified after creation?
Answer : C
Atupleis immutable, which means it cannot be changed after it is created.
Example:
coordinates = (10, 20)
After this tuple is created, its elements cannot be modified directly. Python's data model documentation explains that tuples are immutable, while lists and dictionaries are mutable.
Therefore, the correct answer isC. Tuple.