PCEP-30-02 Dumps
PCEP-30-02 Braindumps PCEP-30-02 Real Questions PCEP-30-02 Practice Test PCEP-30-02 Actual Questions
killexams.com
PCEP - Certified Entry-Level Python Programmer
https://killexams.com/pass4sure/exam-detail/PCEP-30-02
What will be the output of the following code snippet: print(type([]) is list)?
True
False
None
er: A
nation:
xpression type([]) returns the type of an empty list, which is list. The comparison is checks if ds refer to the same object, and since they do, the output will be True.
of the following Python statements will correctly create a list containing the numbers 1 to 1 ve?
mbers = [1:10]
mbers = list(range(1, 11))
mbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
mbers = (1, 10) er: B
nation:
ate a list of numbers from 1 to 10 inclusive, we can use the range function with list() to con ist.
Expla
The e both
operan
Which 0
inclusi
nu
nu
nu
nu Answ
Expla
To cre vert it
into a l
numbers = list(range(1, 11)) produces [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. The other options either use incorrect syntax or create a tuple.
What will be the output of the following code that uses the filter() function? nums = [1, 2, 3, 4, 5]
even_nums = list(filter(lambda x: x % 2 == 0, nums))
print(even_nums)
A. [1, 2, 3]
B. [2, 4]
C. [1, 3, 5]
D. [1, 2, 3, 4, 5]
Answer: B
ill be the output of the following code?
b=1, c=2):
* b + c (5, 2))
function will raise an error. er: A
nation:
function, f takes three parameters, with b and c having default values. When called with 5 f or b, it calculates 5 * 2 + 2, which equals 12.
What w
def f(a, return a
print(f
12
15
20
8
9
The Answ
Expla
In this or a
and 2 f
What will be the output of the following code when executed?
def my_function(x): return x + 1
result = my_function(3) print(result)
2
3
4
nation:
nction my_function takes an argument x, adds 1, and returns the result. For the input 3, it re
der the following snippet of code. What will be printed when the function func is called with ent 4?
nc(n):
n + 1) if n % 2 == 0 else (n - 1) unc(4))
ne er: C
nation:
The fu turns
4.
Consi the
argum def fu return (
print(f
3
4
5
2
No
Answ Expla
When func(4) is called, since 4 is even (4 % 2 == 0), the function returns 4 + 1, which equals 5. Therefore, the printed result is 5.
What will be printed by the following code block?
def func(a, b): a += b
return a x = 10
y = 5 print(func(x, y)) print(x)
A. 15, 10
15, 5
15
er: A nation:
nction func adds b to a and returns the result. It does not modify the original x, so x remains
the output of this code?
uare_numbers(lst):
x**2 for x in lst if x > 0] quare_numbers([-1, 0, 1, 2, 3]))
, 9]
, 4, 9]
, 3]
]
0]
er: A
15,
Answ Expla
The fu 10.
What is
def sq return [ print(s
[1, 4
[0, 1
[1, 2
[2, 3
[-1,
Answ Explanation:
The square_numbers function squares only the positive numbers in the input list. For [-1, 0, 1, 2, 3], the positive numbers are 1, 2, and 3, leading to the output [1, 4, 9].
What does the following code output?
def check_value(x):
return "Positive" if x > 0 else "Negative" if x < 0 else "Zero" print(check_value(-10))
print(check_value(0)) print(check_value(10))
Positive, Negative, Zero
o, Negative, Positive gative, Positive, Zero
er: B nation:
nction checks the value of x and returns "Negative", "Zero", or "Positive" depending on its
ion. The outputs correspond correctly to the inputs.
of the following statements best describes the purpose of the __init__ method in a Python c used to return a string representation of the object.
nitializes the object's attributes when an instance is created. invoked when a class is inherited.
used to delete an instance of the object. er: B
nation:
_init__ method is a special method in Python classes that is automatically called when a new ce of the class is created. It allows you to set the initial state of the object by assigning value
Zer
Ne
Answ Expla
The fu condit
Which lass?
It is
It i
It is
It is Answ
Expla The _
instan s to its
attributes.
A financial institution is developing a Python program to calculate the compound interest on an investment. The program should account for user inputs and provide the final amount after the specified time. You need to complete the code to meet the requirements.
principal = XXX
rate = YYY time = ZZZ
amount = principal * (1 + rate / 100) ** time
print('The final amount after {} years is: {:.2f}'.format(time, amount)) What should you insert instead of XXX, YYY, and ZZZ?
XXX -> float(input('Enter the principal amount: ')) YYY -> float(input('Enter the interest rate: ')) ZZZ
-> int(input('Enter the time in years: '))
XXX -> input('Enter the principal amount: ') YYY -> float(input('Enter the interest rate: ')) ZZZ -> int(input('Enter the time in years: '))
ut('Enter the time in years: '))
X -> float(input('Enter the principal amount: ')) YYY -> float(input('Enter the interest rate: ut('Enter the time in years: ')
er: A nation:
pal = float(input('Enter the principal amount: '))
loat(input('Enter the interest rate: ')) int(input('Enter the time in years: '))
= principal * (1 + rate / 100) ** time
The final amount after {} years is: {:.2f}'.format(time, amount))
ogram captures user inputs for principal and rate as floats, and time as an integer. ulates the compound interest and formats the output to two decimal places.
of the following statements about default parameters in Python functions is true? fault parameters must be specified in every function call.
cannot use mutable types as default parameters.
ault parameters are evaluated only once at function definition time.
XX ')) ZZZ
-> inp Answ
Expla princi rate = f time = amount print(' The pr It calc
Which
De
You
Def Answer: C
Explanation:
Default parameters in Python are evaluated once when the function is defined, not each time the function is called.
What will be the output of the following code snippet involving a class method and class variable? class Counter:
count = 0
def increment(self): Counter.count += 1 counter1 = Counter() counter1.increment() counter2 = Counter() counter2.increment() print(Counter.count)
or er: B
nation:
ass variable count is shared among all instances of the Counter class. Each time increment() count increases by 1. After two calls, the count is 2.
ne the following code snippet and identify which statements regarding the use of *args and rgs in function definitions are true: (Select All That Apply)
nction_with_args(*args, **kwargs): rgs)
wargs)
on_with_args(1, 2, three='3', four='4')
1 2 0 Err Answ Expla The cl is called, Exami **kwa def fu print(a print(k functi The output will be (1, 2) and {'three': '3', 'four': '4'} *args allows for variable numbers of positional arguments **kwargs allows for variable numbers of keyword arguments Both *args and **kwargs can be used in the same function Answer: A, B, C, D Explanation: The *args parameter collects extra positional arguments into a tuple, while **kwargs collects additional keyword arguments into a dictionary. The output confirms that args contains (1, 2) and kwargs contains {'three': '3', 'four': '4'}. Both can be used together in the same function definition. What will be the output of the following code snippet? unc(func(3))) er: C nation: nction func takes an argument x and returns x * 2. unc(3) is called, it returns 6. unc(6) is called, which returns 12. he final output is 12. o you define a function that can take an arbitrary number of positional arguments and keywo ents? my_function(*args, kwargs): print(f 6 3 12 9 Answ Expla The fu When f Then, f Thus, t How d rd argum def def my_function(args, kwargs): def my_function(*args, **args): Answer: A Explanation: The syntax *args captures positional arguments as a tuple, while **kwargs captures keyword arguments as a dictionary. A healthcare application requires a Python program to calculate the Body Mass Index (BMI) from a user's weight and height. The program must handle exceptions for invalid input and provide a clear output. You need to complete the code to meet the requirements. weight = XXX height = YYY try: Height cannot be zero.') Your BMI is: {:.2f}'.format(bmi)) hould you insert instead of XXX and YYY? X -> float(input('Enter your weight in kg: ')) YYY -> float(input('Enter your height in mete X -> input('Enter your weight in kg: ') YYY -> input('Enter your height in meters: ') X -> float(input('Enter your weight in kg: ')) YYY -> input('Enter your height in meters: ') X -> input('Enter your weight in kg: ') YYY -> float(input('Enter your height in meters: ')) er: A nation: = float(input('Enter your weight in kg: ')) = float(input('Enter your height in meters: ')) weight / (height ** 2) ZeroDivisionError: Height cannot be zero.') Your BMI is: {:.2f}'.format(bmi)) ogram captures user input as a float for weight and height. dles division by zero, which can occur if height is zero, and formats the BMI output to two d bmi = weight / (height ** 2) except ZeroDivisionError: print(' else: print(' What s XX rs: ')) XX XX XX Answ Expla weight height try: bmi = except print(' else: print(' The pr It han ecimal places. Which of the following statements correctly illustrates the concept of variable scope in Python? Variables defined inside a function can be accessed from outside the function. Global variables can be modified inside a function using the global keyword. Local variables can be accessed from any part of the program. The scope of a variable is determined by the order of its declaration. Answer: B Explanation: In Python, variables defined inside a function are local to that function and cannot be accessed from outside. To modify a global variable inside a function, you must declare it using the global keyword. ill be printed by the following code snippet when executed? nc(x): 0: x unc(-x) unc(-5)) er: A nation: nction func checks if x is non-negative. unc(-5) is called, -5 is negative, so it calls func(5). unc(5) checks and finds that 5 is non-negative and returns 5. he output will be 5. if x >= return else: return f print(f 5 -5 0 Answ Expla The fu When f Now, f Thus, t When using keyword arguments in a function, which of the following is a valid way to call the function? my_function(x=1, 2) my_function(2, x=1) my_function(2, y=3) Answer: B Explanation: Keyword arguments can be specified in any order. However, positional arguments must appear before keyword arguments. What does the following code output? palindrome(s): == s[::-1] s_palindrome("racecar")) True se ecar er: A nation: nction is_palindrome checks if the string s is the same forwards and backwards. "racecar" is rome, so the output is True. der the following code snippet. What will be the output when this code is executed? erge_dicts(dict1, dict2): A. Fal rac 1 0 Answ Expla The fu a palind Consi def m return {**dict1, **dict2} dict_a = {'a': 1, 'b': 2} dict_b = {'b': 3, 'c': 4} print(merge_dicts(dict_a, dict_b)) A. {'a': 1, 'b': 2, 'c': 4} B. {'a': 1, 'b': 3, 'c': 4} C. {'a': 1, 'b': 2} D. {'b': 3, 'c': 4} Answer: B Explanation: The function merge_dicts combines two dictionaries. If there are overlapping keys, the values from the second dictionary (dict2) take precedence. Hence, the resulting dictionary is {'a': 1, 'b': 3, 'c': 4}.Quest
Question: 441
ion: 442
Quest
Question: 443
Question: 444
Question: 445
Question: 446
Question: 447
ion: 448
Quest