Question: ANSWER THE FOLLOWING QUESTIONs please: 1. Consider the following function definition: def isPal(myStr): myStr is a string. Returns True if myStr is forms a

ANSWER THE FOLLOWING QUESTIONs please:

1.

Consider the following function definition:

def isPal(myStr): """ myStr is a string. Returns True if myStr is forms a palindrom, False otherwise """ temp = myStr temp.reverse if temp == myStr: return True else: return False print(isPal('anna')) This function contains several bugs. When we first call print(isPal('anna')) we get the following error message: AttributeError: 'str' object has no attribute 'reverse'

Select how to modify the code so that this error only does not occur (do not pick the solutions that fix other bugs).

a.

Insert at the beginning of the block of code: myStr = list(myStr)

b. Replace temp = myStr by temp = myStr[:]

c. Replace if temp == myStr: by if temp == list(myStr):

d.

Replace temp.reverse by temp.reverse()

2. Which of the following is NOT a tuple in Python?

a.

('a', 1)

b.

(('a', 'b', 'c'))

c. All of these expressions are tuples.

d.

(())

e.

('a', 'b')

f.

('a')

3. Which of the following is NOT needed in every recursive function in Python:

a. All of these statements are needed for a recursive function.

b. a base case

c. a recursive case

d.

an explicit return statement

4. Suppose the following statement:

a = b

causes a NameError, because name 'b' is not defined.

That is an example of an error in:

a. semantics

b. syntax

c. static semantics

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!