PCEP-30-01 Dumps

PCEP-30-01 Braindumps PCEP-30-01 Real Questions PCEP-30-01 Practice Test PCEP-30-01 Actual Questions


AICPA


PCEP-30-01


Certified Entry-Level Python Programmer


https://killexams.com/pass4sure/exam-detail/PCEP-30-01

Question: 34


A function definition starts with the keyword:

  1. def

  2. function

  3. fun


Answer: A Explanation: Topic: def

Try it yourself:


def my_first_function(): print(‘Hello’) my_first_function() # Hello

https://www.w3schools.com/python/python_functions.asp


Question: 35


Consider the following code snippet: w = bool(23)

x = bool(”)


y = bool(‘ ‘)


z = bool([False])


Which of the variables will contain False?

  1. z

  2. x

  3. y

  4. w


Answer: 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

Question: 36


Assuming that the tuple is a correctly created tuple,

the fact that tuples are immutable means that the following instruction: my_tuple[1] = my_tuple[1] + my_tuple[0]

  1. can be executed if and only if the tuple contains at least two elements

  2. is illegal

  3. may be illegal if the tuple contains strings

  4. is fully correct


Answer: B Explanation: Topics: dictionary

Try it yourself: my_tuple = (1, 2, 3)

my_tuple[1] = my_tuple[1] + my_tuple[0]


# TypeError: ‘tuple’ object does not support item assignment A tuple is immutable and therefore you cannot

assign a new value to one of its indexes.


Question: 37


You develop a Python application for your company. You have the following code.

def main(a, b, c, d): value = a + b * c – d return value

Which of the following expressions is equivalent to the expression in the function? A. (a + b) * (c – d)

  1. a + ((b * c) – d)

  2. None of the above. D. (a + (b * c)) – d


Answer: D Explanation:

Topics: addition operator multiplication operator subtraction operator operator precedence

Try it yourself:


def main(a, b, c, d): value = a + b * c – d # 3

# value = (a + (b * c)) – d # 3


# value = (a + b) * (c – d) # -3


# value = a + ((b * c) – d) # 3 return value

print(main(1, 2, 3, 4)) # 3


This question is about operator precedence


The multiplication operator has the highest precedence and is therefore executed first. That leaves the addition operator and the subtraction operator

They both are from the same group and therefore have the same precedence. That group has a left-to-right associativity.

The addition operator is on the left and is therefore executed next. And the last one to be executed is the subtraction operator Question: 38

Which of the following variable names are illegal? (Select two answers)

  1. TRUE

  2. True

  3. true

  4. and


Answer: B, D Explanation:

Topics: variable names keywords True and Try it yourself:

TRUE = 23


true = 42


# True = 7 # SyntaxError: cannot assign to True


# and = 7 # SyntaxError: invalid syntax You cannot use keywords as variable names. Question: 39

Which of the following for loops would output the below number pattern?


  1. for i in range(0, 5): print(str(i) * 5)

  2. for i in range(1, 6): print(str(i) * 5)

  3. for i in range(1, 6): print(i, i, i, i, i)

  4. for i in range(1, 5): print(str(i) * 5)


Answer: B Explanation:

Topics: for range() str() multiply operator string concatenation Try it yourself:

for i in range(1, 6): print(str(i) * 5)

""" 11111

22222


33333


44444


55555 """

print(‘———-‘) for i in range(0, 5): print(str(i) * 5)

"""


"""


print(‘———-‘) for i in range(1, 6): print(i, i, i, i, i)

"""


1 1 1 1 1


2 2 2 2 2


3 3 3 3 3


4 4 4 4 4


5 5 5 5 5 """

print(‘———-‘) for i in range(1, 5): print(str(i) * 5)

""" 11111

22222


33333


44444 """

You need range (1, 6)


because the start value 1 is inclusive and the end value 6 is exclusive. To get the same numbers next to each other (without a space between them) you need to make a string and then use the multiply operator string concatenation


The standard separator of the print() function is one space. print(i, i, i, i, i) gives you one space between each number. It would work with print(i, i, i, i, i, sep=”) but that answer is not offered here.

The digraph written as #! is used to:

  1. tell a Unix or Unix-like OS how to execute the contents of a Python file.

  2. create a docstring.

  3. make a particular module entity a private one.

  4. tell an MS Windows OS how to execute the contents of a Python file.


Answer: A Explanation: Topics: #! shebang

This is a general UNIX topic. Best read about it here:

https://en.wikipedia.org/wiki/Shebang_(Unix)