Ask Question

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).

+1
Answers (1)
  1. 16 May, 16:56
    0
    def recursive_func ():

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

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

    return

    else:

    recursive_func ()

    recursive_func ()

    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).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a recursive program that requests an answer to the question "Are we there yet?" using an input statement and terminates if the user ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers