Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Jill points out to Jack that English grammar allows a noun to be modified by zero or more adjectives. Examples are The girl hit the

Jill points out to Jack that English grammar allows a noun to be modified by zero or more adjectives. Examples are The girl hit the ball,The girl hit the red ball, and The girl hit the little red ball. She asks Jack to design and implement a function to generate noun phrases based on the following grammar rules:
nounphrase = article [adjectivephrase] noun
adjectivephrase = adjective [adjectivephrase]
where an adjective phrase is one or more adjectives (remember that the[] brackets indicate an optional item in a grammar rule). Jacks code for the nounPhrase and adjectivePhrase functions follows:
#nounphrase = article [adjectivephrase] noun
def nounPhrase():
"""Builds and returns a noun phrase."""
return random.choice(articles)+""+\
adjectivePhrase()+""+ random.choice(nouns)
#adjectivephrase = adjective [adjectivephrase]
def adjectivePhrase():
"""Builds and returns an adjective phrase."""
return random.choice(adjectives)+""+ adjectivePhrase()
When Jack tests the nounPhrase function, the PVM halts the program with a RecursionError. Determine why this error occurs and correct it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

Students also viewed these Databases questions

Question

=+ Have they changed the way employers view IP?

Answered: 1 week ago