Certification exams validate your expertise to show potential schools, scholarships, and employers that you are serious about your education and career.
The OpenEDG Python Institute administers this progression of Python certification exams:
70% is the threshold for passing for all exams.
Prices above are for a single try. Exams can be purchased with a retake option and sample tests.
Cisco’s offers at their NetAcad.com site free online Python courses developed in collaboration with OpenEDG:
Login using your Google account and associated password.
In Credly, click Settings, Security & Privacy, to setup two-factor authentication with your Authy mobile app.
Click “Submit” for your score. Hopefully you’ll see “Congratulations, you have passed the assessment.”
DOTHIS: Email me the discount code so I can send you the exam code.
When you get the exam code, visit https://pearsonvue.com/pythoninstitute to register for the exam.
Repeat as above.
Passing this prep exam gets you a discount coupon for 50% ($150) off the actual $295 exam fee for a cost to you of $144.
Python Advanced 1 (Advanced OOP)
def o(p):
def q():
return '*' * p
return q
r = o(1)
s = o(2)
print(r() + s())
This is an example of a “closure” in Python.
The inner function o is a function factory - it creates functions on the fly and returns functions instead of a value. It allows for dynamic (parameterized) function generation with customizable behavior.
https://realpython.com/factory-method-python/
The inner function q “remembers” the value of p that was passed to the outer function o. Each call to o creates a new function with its own “remembered” value of p.
https://www.youtube.com/watch?v=JIImCgkAQxY&t=61s
Look at the following code:
numbers = [0, 2, 7, 9, 10]
# Insert line of code here to produce [0, 4, 49, 81, 100]
print(foo)
Which line would you insert in order for the program to produce the expected output?
Choices given for the question suggests use of lambda within filter() and map() functions, all within a list:
a) foo = lambda num: num * 2, numbers
b) foo = lambda num: num ** 2, numbers
c) foo = filter(lambda num: num ** 2, numbers
)
d) foo = map(lambda num: num ** 2, numbers)
Before looking at the answers, we can see that the output sought (in foo) is the square of the input numbers:
To calculate a square, we use num ** 2
QUESTION: What does the filter function do?
filter() is a built-in function that takes two parameters: a function (such as lambda) and an iterable (like a list, tuple, or set) and returns an iterator containing only the elements for which the function returns True.
The answer yields an internal Python object ID and its value from lambda:
(<function
foo = list(filter(lambda num: num ** 2, numbers))
A more complex question uses a list comprehension [i*i for i in range(5)]
numbers = [i*i for i in range(5)]
# Insert line of code here to produce [1, 9]
print(foo)
Before looking at the answers, what value is contained in the numbers variable?
range(5) produces 5 values, from 0 to 4:
[0, 1, 2, 3, 4]
QUESTION: What does the i*i do?
It multiples i by itself (turning into a square of itself), yielding:
numbers = [0, 1, 4, 9, 16]
The question is asking for [1, 9] to be produced.
So that’s the second and fourth item from the five-item input list, which are the even numbers.
x % 2 reminders would yield even numbers.
That is shown by:
print(lambda x: x % 2, numbers)
which shows internal Python object ID and its value from lambda:
<function
The list() function extracts out the values of [0, 1, 4, 9, 16].
Now the choices given for the question:
a) foo = list(map(lambda x: x // 2, numbers))
b) foo = list(map(lambda x: x % 2, numbers))
c) foo = list(filter(lambda x: x / 2, numbers))
d) foo = list(filter(lambda x: x % 2, numbers))
The filter() function with lambda x: x % 2 does the following: x % 2 returns 1 (truthy) for odd numbers x % 2 returns 0 (falsy) for even numbers
This effectively keeps only the odd numbers in the list So filter(lambda x: x % 2, numbers) will keep only the odd squares: [1, 9]
QUESTION: What does the map function do?
That’s put there as a distractor.
The map() function is a built-in Python function that transforms iterables by applying a specified function to each item in an iterable.
Perplexity.ai says the answer is b:
foo = list(filter(lambda x: x % 2, numbers))
This makes use of some methods for the random package described at https://docs.python.org/3/library/random.html
import random
# Insert lines of code here.
print(a, b, c)
Which lines of code would you insert so that it is possible for the program to output the following result:
6 82 0
Analysis:
Running the code provided is unlikely to yield “6 82 0” because the methods used generate random numbers.
https://docs.python.org/3/library/random.html#random.randint
random.randrange(10, 100, 3) # Returns a randomly selected element from range(start, stop, step).
random.randint(0, 100) # Returns a random integer N such that a <= N <= b
random.choice((0, 100, 3)) # Returns a random element from the non-empty sequence
Each set (A,B,C,D) uses output variables a,b,c using different random.methods.
Let’s analyze each command to see if it can yield “6 82 0”.
A:
a = random.randrange(10, 100, 3)
# Doesn’t qualify because 6 is < 10.
b = random.randint(0, 100)
# Can qualify because 92 can be between 0 to 100.
c = random.choice((0, 100, 3))
# Can qualify because 92 can be 0.
B:
a = random.choice((0, 100, 3))
b = random.randrange(10, 100, 3)
# Doesn’t qualify because 82 is not divisible by 3.
c = random.randint(0, 100)
C:
a = random.randint(0, 100)
b = random.randrange(10, 100, 3)
# Doesn’t qualify because 82 is not divisible by 3.
c = random.choice((0, 100, 3))
D:
a = random.randint(0, 100)
b = random.choice((0, 100, 3))
# Doesn’t qualify because 82 is not divisible by 3.
c = random.randrange(10, 100, 3)
REMEMBER: The answer choice is rearranged by the testing software:
a) B
b) C
c) D
d) A
So no good choices?