OF PROGRAMMING (PYTHON) EXAM | ALL QUESTIONS
AND CORRECT ANSWERS | VERIFIED ANSWERS | JUST
RELEASED
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?
if number > 0:
if number != 0:
if number < 0:
if number >= 1 ---------CORRECT ANSWER-----------------if number > 0:
Complete the function double_number(num) that takes one number
parameter and returns double that number.
For example, double_number(5) should return 10.
def double_number(num):
# TODO: Return double the input number
,# Example: double_number(5) should return 10
pass ---------CORRECT ANSWER-----------------def double_number(num):
return num * 2
Modify the function greet_with_default(name) by adding a default
value of "World" to the name parameter so it can be called with or
without an argument.
def greet_with_default(name):
# TODO: Add a default value of "World" to the name parameter
return "Hello " + name ---------CORRECT ANSWER-----------------def
greet_with_default(name="World"):
return "Hello " + name
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 ---------CORRECT ANSWER-----------------def is_positive(number):
return number > 0
, Which symbol begins a single-line comment in Python?
// (double forward slash)
# (pound symbol)
* (asterisk)
% (percent symbol) ---------CORRECT ANSWER-----------------# (pound
symbol)
Which data type is the value 3.14 in Python?
Integer
Float
String
Boolean ---------CORRECT ANSWER-----------------Float
In Python, what must follow the in keyword in a for loop?
A condition
An iterable object
A number
A variable name ---------CORRECT ANSWER-----------------An iterable
object