Python Institute PCEP-30-01 Certified Entry-Level Python Programmer Online Training
Python Institute PCEP-30-01 Online Training
The questions for PCEP-30-01 were last updated at Nov 23,2024.
- Exam Code: PCEP-30-01
- Exam Name: Certified Entry-Level Python Programmer
- Certification Provider: Python Institute
- Latest update: Nov 23,2024
The value thirty point eleven times ten raised to the power of nine should be written as:
- A . 30.11E9
- B . 30E11.9
- C . 30.11E9.0
- D . 30.11*10^9
A
Explanation:
Topic: scientific notation
Try it yourself:
print(30.11E9) # 30110000000.0
# print(30E11.9) # SyntaxError: invalid syntax
# print(30.11E9.0) # SyntaxError: invalid syntax
# print(30.11*10^9) # TypeError: unsupported operand …
print(30.11 * 10 ** 9) # 30110000000.0
You could replace the E by * 10 **
The ABC organics company needs a simple program that their call center will use to enter survey data for a new coffee variety. The program must accept input and return the average rating based on a five-star scale.
The output must be rounded to two decimal places.
You need to complete the code to meet the requirements.
sum = count = done = 0
average = 0.0
while done != -1:
rating = XXX
if rating == -1:
break
sum += rating
count += 1
average = float(sum / count)
YYY + ZZZ
What should you insert instead of XXX, YYY and ZZZ?
- A . XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2d’)) - B . XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> printline(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2f’)) - C . XXX -> print(input(‘Enter next rating (1-5), -1 for done’))
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2f’)) - D . XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> output(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2d’)) - E . XXX -> float(input(‘Enter next rating (1-5), -1 for done’))
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2f’)) - F . XXX -> input(‘Enter next rating (1-5), -1 for done’)
YYY -> print(‘The average star rating for the new coffee is: ‘
ZZZ -> format(average, ‘.2d’))
E
Explanation:
Topics: while not equal to operator if
add and assign operator float()
division operator format()
plus operator string concatenation
Try it yourself:
sum = count = done = 0
average = 0.0
while done != -1:
rating = float(input(‘Enter next rating (1-5), -1 for done’))
if rating == -1:
break
sum += rating
count += 1
average = float(sum / count)
print(‘The average star rating for the new coffee is: ‘ + format(average, ‘.2f’))
# format(average, ‘.2d’) -> ValueError: …
The input() function always returns a string
You need to cast that string to a float with the float() function.
The function to print something to the monitor is called print()
And if you want to round a float to two decimal places,
you need the format string ‘.2f’
Consider the following code snippet:
w = bool(23)
x = bool(”)
y = bool(‘ ‘)
z = bool([False])
Which of the variables will contain False?
- A . z
- B . x
- C . y
- D . w
B
Explanation:
Topic: type casting with bool()
Try it yourself:
print(bool(23)) # True
print(bool(”)) # False
print(bool(‘ ‘)) # True
print(bool([False])) # True
The list with the value False is not empty and therefore it becomes True
The string with the space also contain one character
and therefore it also becomes True
The values that become False in Python are the following:
print(bool(”)) # False
print(bool(0)) # False
print(bool(0.0)) # False
print(bool(0j)) # False
print(bool(None)) # False
print(bool([])) # False
print(bool(())) # False
print(bool({})) # False
print(bool(set())) # False
print(bool(range(0))) # False
What is the expected output of the following code?
def func(num):
res = ‘*’
for _ in range(num):
res += res
return res
for x in func(2):
print(x, end=”)
- A . **
- B . The code is erroneous.
- C . *
- D . ****
D
Explanation:
Topics: def return for
Try it yourself:
def func(num):
res = ‘*’
for _ in range(num):
res += res
return res
for x in func(2):
print(x, end=”) # ****
# print(x, end=’-‘) # *-*-*-*-
print()
print(func(2)) # ****
The for loop inside of the function will iterate twice.
Before the loop res has one star.
In the first iteration a second star is added.
res then has two stars.
In the second iteration two more stars are added to those two star and res will end up with four stars.
The for loop outside of the function will just iterate through the string and print every single star.
You could get that easier by just printing the whole return value.
What is the expected output of the following code?
num = 1
def func():
num = num + 3
print(num)
func()
print(num)
- A . 4 1
- B . 4 4
- C . The code is erroneous.
- D . 1 4
- E . 1 1
C
Explanation:
Topics: def shadowing
Try it yourself:
num = 1
def func():
# num = num + 3 # UnboundLocalError: …
print(num)
func()
print(num)
print(‘———-‘)
num2 = 1
def func2():
x = num2 + 3
print(x) # 4
func2()
print(‘———-‘)
num3 = 1
def func3():
num3 = 3 # Shadows num3 from outer scope
print(num3) # 3
func3()
A variable name shadows into a function.
You can use it in an expression like in func2()
or you can assign a new value to it like in func3()
BUT you can not do both at the same time like in func()
There is going to be the new variable num
and you can not use it in an expression before its first assignment.
The result of the following addition:
123 + 0.0
- A . cannot be evaluated
- B . is equal to 123.0
- C . is equal to 123
B
Explanation:
Topics: addition operator integer float
Try it yourself:
print(123 + 0.0) # 123.0
If you have an arithmetic operation with a float,
the result will also be a float.
What is the expected output of the following code?
print(list(‘hello’))
- A . None of the above.
- B . hello
- C . [h, e, l, l, o]
- D . [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
- E . [‘h’ ‘e’ ‘l’ ‘l’ ‘o’]
D
Explanation:
Topic: list()
Try it yourself:
print(list(‘hello’)) # [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
A string is a sequence of characters
and works very fine with the list() function.
The result is a list of strings, in which every character is a string of its own.
What is the default return value for a function
that does not explicitly return any value?
- A . int
- B . void
- C . None
- D . Null
- E . public
C
Explanation:
Topic: return
Try it yourself:
def func1():
pass
print(func1()) # None
def func2():
return
print(func2()) # None
If a function does not have the keyword return the function will return the value None
The same happens if there is no value after the keyword return
Which of the following lines correctly invoke the function defined below:
def fun(a, b, c=0):
# Body of the function.
(Select two answers)
- A . fun(0, 1, 2)
- B . fun(b=0, a=0)
- C . fun(b=1)
- D . fun()
A,B
Explanation:
Topics: functions positional parameters keyword parameters
Try it yourself:
def fun(a, b, c=0):
# Body of the function.
pass
fun(b=0, a=0)
fun(0, 1, 2)
# fun() # TypeError: fun() missing 2 required
# positional arguments: ‘a’ and ‘b’
# fun(b=1) # TypeError: fun() missing 1 required
# positional argument: ‘a’
Only the parameter c has a default value.
Therefore you need at least two arguments.
What is the expected output of the following code?
x = ”’
print(len(x))
- A . 1
- B . 2
- C . The code is erroneous.
- D . 0
A
Explanation:
Topics: len() escaping
Try it yourself:
print(len(”’)) # 1
The backslash is the character to escape another character.
Here the backslash escapes the following single quote character.
Together they are one character.