[Aug 18, 2026] Foundations-of-Programming-Python Exam Dumps PDF Guaranteed Success with Accurate Updated Questions Pass Foundations-of-Programming-Python Exam - Real Test Engine PDF with 62 Questions NEW QUESTION # 25 Complete the function is_positive(number) that returns True if the number is greater than 0, and False otherwise.def is_positive(number):# TODO: Return True if number 0, False otherwisepass [...]

[Aug 18, 2026] Foundations-of-Programming-Python Exam Dumps PDF Guaranteed Success with Accurate & Updated Questions [Q25-Q47]

Share

[Aug 18, 2026] Foundations-of-Programming-Python Exam Dumps PDF Guaranteed Success with Accurate & Updated Questions

Pass Foundations-of-Programming-Python Exam - Real Test Engine PDF with 62 Questions

NEW QUESTION # 25
Complete the function is_positive(number) that returns True if the number is greater than 0, and False otherwise.
def is_positive(number):
# TODO: Return True if number > 0, False otherwise
pass

Answer:

Explanation:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The function receives one parameter named number.
Step 2: The condition number > 0 checks whether the number is positive.
Step 3: In Python, this comparison already returns either True or False.
Correct code:
def is_positive(number):
return number > 0
Example:
print(is_positive(5))
print(is_positive(-2))
print(is_positive(0))
Output:
True
False
False


NEW QUESTION # 26
Which symbol begins a single-line comment in Python?

  • A. * asterisk
  • B. # pound symbol
  • C. // double forward slash
  • D. % percent symbol

Answer: B

Explanation:
In Python, a single-line comment begins with the # symbol.
Example:
# This is a comment
print( " Hello " )
Python ignores the comment when the program runs. The Python documentation identifies # as the symbol used for comments.
Therefore, the correct answer isB. # pound symbol.


NEW QUESTION # 27
Which for loop correctly iterates through a list of student names?

  • A. for name from [ ' Alice ' , ' Bob ' , ' Carol ' ]:
  • B. for name = [ ' Alice ' , ' Bob ' , ' Carol ' ]
  • C. for name in [ ' Alice ' , ' Bob ' , ' Carol ' ]:
  • D. for name with [ ' Alice ' , ' Bob ' , ' Carol ' ]:

Answer: C

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


NEW QUESTION # 28
Which keyword moves a loop immediately to its subsequent iteration?

  • A. continue
  • B. jump
  • C. advance
  • D. pass

Answer: A

Explanation:
The Python keyword continue is used inside a loop to skip the rest of the current iteration and move immediately to the next iteration.
Example:
for number in range(5):
if number == 2:
continue
print(number)
Output:
0
1
3
4
When number is 2, the continue statement skips print(number) for that iteration and moves to the next loop cycle.
The official Python documentation states that the continue statement continues with the next iteration of the loop.
Therefore, the correct answer is C. continue.


NEW QUESTION # 29
What sequence of steps is required to execute a Python script from a text editor using the terminal on a Windows device?

  • A. Save file > open terminal > type python filename.py
  • B. Save file > close text editor > open different IDE
  • C. Open terminal > write code directly > press Enter
  • D. Save file > compile code > run executable

Answer: A

Explanation:
To run a Python script from a text editor using the terminal on Windows, the file should first be saved with the .py extension. Then, the terminal is opened, and the script is executed using the Python command followed by the filename.
Example:
python filename.py
The official Python documentation explains that when the interpreter is called with a filename argument, it reads and executes the script from that file. On Windows, the python command can be used from a terminal after Python is installed and configured correctly.
Therefore, the correct answer is A. Save file > open terminal > type python filename.py.


NEW QUESTION # 30
A dictionary prices = { ' apple ' : 1.50, ' banana ' : 0.75, ' orange ' : 2.00} needs to have all values increased by
0.25. Which code correctly accomplishes this task?

  • A. for prices in item:prices = prices + 0.25
  • B. for value in prices:value = value + 0.25
  • C. for item in prices:prices[item] = prices[item] + 0.25

Answer: C

Explanation:
In Python, iterating directly over a dictionary gives itskeys. In this dictionary, the keys are:
' apple '
' banana '
' orange '
To update each price, the program can loop through each key and use that key to access and change the corresponding value.
Correct code:
prices = { ' apple ' : 1.50, ' banana ' : 0.75, ' orange ' : 2.00}
for item in prices:
prices[item] = prices[ item] + 0.25
print(prices)
Output:
{ ' apple ' : 1.75, ' banana ' : 1.0, ' orange ' : 2.25}
Option B is incorrect because value actually receives each dictionary key, not each dictionary value. Also, assigning to value would not update the dictionary.
Option C is incorrect because item is not defined, and the loop structure is invalid for this task.


NEW QUESTION # 31
What does the string method ' ' .join() return when applied to the list [ ' Hello ' , ' World ' ]?

  • A. ' Hello,World '
  • B. ' Hello World '
  • C. ' HelloWorld '
  • D. ' Hello, World '

Answer: C

Explanation:
The string method join() combines the strings in an iterable using the string before .join() as the separator.
In this question, the separator is an empty string:
' ' .join([ ' Hello ' , ' World ' ])
Because the separator is empty, Python joins ' Hello ' and ' World ' directly together with no space or comma between them.
Result:
' HelloWorld '
The official Python documentation defines str.join() as returning a string made by joining the strings in the given iterable.
Therefore, the correct answer is B. ' HelloWorld ' .


NEW QUESTION # 32
Which loop structure processes every individual item in a list called grades?

  • A. while grades[0]
  • B. while len(grades) > 0:
  • C. for grade in grades:
  • D. for i in range(grades):

Answer: C

Explanation:
The loop:
for grade in grades:
print(grade)
processes every individual item in the list grades.
The variable grade represents the current item being processed. Python's documentation explains that a for statement iterates over the items of a sequence in order.
Therefore, the correct answer isB. for grade in grades:.


NEW QUESTION # 33
A program needs to display only positive, non-zero numbers from a list containing a mixture of integer and decimal values. Which conditional statement should be placed inside the loop?

  • A. if number != 0:
  • B. if number > = 1:
  • C. if number > 0:
  • D. if number < 0:

Answer: C

Explanation:
To display only positive, non-zero numbers, the condition should check whether each number is greater than 0.
Correct condition:
if number > 0:
Example:
numbers = [-2, 0, 1, 3.5, -4.2]
for number in numbers:
if number > 0:
print(number)
Output:
1
3.5
The condition number > 0 works for both integers and decimal values. The condition number > = 1 would incorrectly exclude positive decimal values such as 0.5.
Therefore, the correct answer isA. if number > 0:.


NEW QUESTION # 34
Which data type does the expression 5 > 3 evaluate to in Python?

  • A. String
  • B. Boolean
  • C. Integer
  • D. Float

Answer: B

Explanation:
In Python, comparison expressions such as 5 > 3 evaluate to aBooleanvalue.
The expression:
5 > 3
checks whether 5 is greater than 3. Since this statement is true, Python returns:
True
True and False are Boolean values in Python.
Therefore, the correct answer isC. Boolean.


NEW QUESTION # 35
Which tool is used to execute Python code line-by-line interactively within a terminal?

  • A. Debugger
  • B. Python shell
  • C. File explorer
  • D. Text editor

Answer: B

Explanation:
The Python shell allows Python code to be entered and executed interactively, one line at a time.
Example:
> > > 2 + 3
5
Python's documentation explains that when commands are read from a terminal, the interpreter is in interactive mode and prompts for the next command.
Therefore, the correct answer isA. Python shell.


NEW QUESTION # 36
Which type of loop repeatedly checks a condition to determine whether to continue?

  • A. while loop
  • B. for loop
  • C. range loop
  • D. repeat loop

Answer: A

Explanation:
Awhile looprepeatedly executes a block of code as long as its condition remains true.
Example:
count = 1
while count < = 3:
print(count)
count += 1
In this example, Python checks the condition count < = 3 before each loop iteration. If the condition is true, the loop continues. When the condition becomes false, the loop stops.
A for loop is usually used to iterate over a sequence, such as a list, string, or range. Python does not have a built-in repeat loop construct.
Therefore, the correct answer isB. while loop.


NEW QUESTION # 37
Fix the off-by-one error in this function that should return the first 3 characters of a string.
def first_three(text):
return text[0:2]

Answer:

Explanation:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: Python string slicing uses this format:
text[start:stop]
Step 2: The start index is included.
Step 3: The stop index is excluded.
Step 4: To return the first 3 characters, start at index 0 and stop at index 3.
Correct code:
def first_three(text):
return text[0:3]
Simplified correct code:
def first_three(text):
return text[:3]
Example:
print(first_three( " Python " ))
Output:
Pyt


NEW QUESTION # 38
Which Python data structure automatically prevents duplicate values from being stored?

  • A. Tuple
  • B. Dictionary
  • C. Set
  • D. List

Answer: C

Explanation:
Asetstores only unique elements. If duplicate values are added, Python keeps only one copy.
Example:
numbers = {1, 2, 2, 3}
print(numbers)
Output:
{1, 2, 3}
Python's data structures documentation describes sets as collections with no duplicate elements.
Therefore, the correct answer isD. Set.


NEW QUESTION # 39
What happens when theRunbutton is clicked in a Python development environment?

  • A. The code is converted to a different programming language.
  • B. A file browser window opens.
  • C. The currently open Python script is executed.
  • D. The file is saved without being executed.

Answer: C

Explanation:
In a Python development environment, clicking theRunbutton generally executes the currently open Python script or selected code.
For example, if the current script contains:
print( " Hello, Python! " )
clickingRunexecutes the script and displays the output:
Hello, Python!
In Python's IDLE environment, theRun Modulecommand runs the current module. The Python documentation describes IDLE as Python's editor and shell and includes a Run menu for running Python code.
The Run button does not simply open a file browser, save the file without execution, or convert Python code into another programming language.
Therefore, the correct answer isB. The currently open Python script is executed.


NEW QUESTION # 40
Which action allows a Python script located in a different folder to be executed in the terminal?

  • A. Use the edit command to open the script first
  • B. Rename the script to match the terminal ' s path
  • C. Use the cd command to navigate to the script ' s directory
  • D. Move the script to your desktop

Answer: C

Explanation:
To run a Python script from the terminal, the terminal should be in the correct directory, or the full file path should be provided.
The cd command is commonly used to change directories before running the script.
Example:
cd Documents
python my_script.py
Python's documentation explains that Python can execute a script when the interpreter is called with a filename argument.
Therefore, the correct answer isC. Use the cd command to navigate to the script ' s directory.


NEW QUESTION # 41
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

Answer:

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


NEW QUESTION # 42
Which terminal command is used to navigate to a different directory before running a Python script?

  • A. move
  • B. goto
  • C. nav
  • D. cd

Answer: D

Explanation:
The command cd means "change directory." It is used in a terminal to move from one folder to another.
Example:
cd Desktop
After navigating to the correct folder, a Python script can be run with a command such as:
python script.py
Therefore, the correct answer isC. cd.


NEW QUESTION # 43
In the code for item in my_list:, what does item represent?

  • A. The current element being processed
  • B. The entire list
  • C. The length of the list
  • D. The index of the current element

Answer: A


NEW QUESTION # 44
Which components are required in every Python for loop?

  • A. A list index, a range limit, and a step value
  • B. A variable, an iterable, and an indented code block
  • C. A condition, a counter, and a break statement
  • D. A function call, a parameter, and a return value

Answer: B

Explanation:
A Python for loop is used to iterate over an iterable object, such as a list, tuple, string, dictionary, set, or range() object.
A basic for loop needs:
A loop variable
An iterable object
An indented code block
Example:
for number in range(3):
print(number)
In this example:
number is the loop variable.
range(3) is the iterable.
print(number) is the indented code block that runs during each loop iteration.
According to the official Python documentation, the for statement is a construct that works with iterable objects.
Therefore, the correct answer is A. A variable, an iterable, and an indented code block.


NEW QUESTION # 45
Write a complete function reverse_string(text) that takes a string and returns it reversed.
For example, reverse_string( " hello " ) should return " olleh " .
def reverse_string(text):
# TODO: Return the reversed string
pass

Answer:

Explanation:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The function receives one string parameter named text.
Step 2: Python slicing can be used to reverse a string.
Step 3: The slice [::-1] means start at the end of the string and move backward by one character at a time.
Step 4: Return text[::-1].
Correct code:
def reverse_string(text):
return text[::-1]
Example:
print(reverse_string( " hello " ))
Output:
olleh


NEW QUESTION # 46
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:

Explanation:
See the Step by Step Solution below in Explanation.
Explanation:
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


NEW QUESTION # 47
......

Get New Foundations-of-Programming-Python Certification Practice Test Questions Exam Dumps: https://examcollection.guidetorrent.com/Foundations-of-Programming-Python-dumps-questions.html