Question: Below are examples of Python functions that act as recognizers or deciders. For each of the functions, What is the language the function recognizes? Use
Below are examples of Python functions that act as recognizers or deciders. For each of the functions,
What is the language the function recognizes? Use setbuilder notation if appropriate.
Is the function a decider or just a recognizer? Why?
For this exercise, let Sigma ab meaning that you only need to consider input strings made of as and bs
a Answer the questions above about this function:
def arthurw: str bool:
length lenw
if length :
return False
# Indices within strings range from the first
# character to length the last character
for i in range length :
if wia or wlength ib:
return False
return True
b Answer the questions above about this function:
def zaphodw: str bool:
strings
while True:
nextstrings
for x in strings:
if w x:
return True
nextstrings.appendx a
nextstrings.appendx b
# On the next iteration through the while loop,
# use nextstrings for the for loop.
strings nextstrings
c Answer the questions above about this function:
def trillianw: str bool:
x
y
while lenw x:
z x y
x y
y z
return True
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
