WGU - Big Savings Alert – Don’t Miss This Deal - Ends In 1d 00h 00m 00s Coupon code: 26Y30OFF
  1. Home
  2. WGU
  3. Foundations-of-Programming-Python Exam
  4. Free Foundations-of-Programming-Python Questions

Free Practice Questions for WGU Foundations of Programming Python Exam

Pass4Future also provide interactive practice exam software for preparing WGU Foundations of Programming (Python) - E010 JIV1 (Foundations of Programming Python) Exam effectively. You are welcome to explore sample free WGU Foundations of Programming Python Exam questions below and also try WGU Foundations of Programming Python Exam practice test software.

Page:    1 / 14   
Total 60 questions

Question 1

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']:.


Question 2

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.


Question 3

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


Question 4

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


Question 5

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.


Page:    1 / 14   
Total 60 questions