201k views
1 vote
Write a recursive program that requests an answer to the question "Are we there yet?" using an input statement and terminates if the user answers 'yes', but executes a recursive call if the user answers anything else (do not use any loops in this program).

User Vvk
by
5.0k points

1 Answer

5 votes

Answer:

def recursive_func():

x = input("Are we there yet?")

if x.casefold() == 'Yes'.casefold():

return

else:

recursive_func()

recursive_func()

Step-by-step explanation:

We define the required function as recursive_func().

The first line takes user input. The user input is stored in variable x.

The next line compares the user input to a string yes. The function executes the else block if the condition isn't met, that is a recursive call is executed.

IF condition returns the function. The string in variable X is compared to a string 'Yes'. the casefold() is a string function that ignores the upper/lower cases when comparing two strings. (This is important because a string 'yes' is not the same yes a string 'Yes' or 'YES'. Two equal strings means their cases and length should match).

User Prakashchhetri
by
4.8k points