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 set-builder notation if appropriate.
Is the function a decider or just a recognizer? Why?
For this exercise, let \Sigma ={a,b}, meaning that you only need to consider input strings made of as and bs.
a. Answer the questions above about this function:
def arthur(w: str)-> bool:
length = len(w)
if length %2==1:
return False
# Indices within strings range from 0(the first
# character) to length -1(the last character).
for i in range(0, length /2):
if (w[i]!="a") or (w[length -1- i]!="b"):
return False
return True
b. Answer the questions above about this function:
def zaphod(w: str)-> bool:
strings =[""]
while True:
next_strings =[]
for x in strings:
if w == x:
return True
next_strings.append(x +"a")
next_strings.append(x +"b")
# On the next iteration through the while loop,
# use next_strings for the for loop.
strings = next_strings
c. Answer the questions above about this function:
def trillian(w: str)-> bool:
x =0
y =1
while len(w)!= x:
z = x + y
x = y
y = z
return True
Below are examples of Python functions that act

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 Programming Questions!