rainbow7020
16.10.2020 •
Computers and Technology
Consider the following segment of code, which prompts the user for a string of lowercase characters (no capitals, spaces, digits, or punctuation) and prints True if the string is palindrome and false otherwise. This implementation is recursive and uses a deque. Because the user expects to provide a string instead of a deque instance, we use a wrapper function. The user calls is_palindrome and provides a string. is_palindrome forms a deque with the contents of the string and sends the deque object to the recursive rec_palindrome function. Both functions return Boolean values. Be sure not to include any unnecessary spaces in your answers. For example, keywords like and and or need spaces around them.
Operators such as== as and < do not.
from Deque_Generator import get _deque
def rec palindrome (dq): if return else:
if
return
else:
return
def is_palindrome (character_string)
dq-get_dequeO
for c in character_string:
return
print(is_palindrome (input ("Enter a phrase of lowercase characters only: ")))
Solved
Show answers
More tips
- S Sport How to Pump Your Chest Muscle? Secrets of Training...
- H Horoscopes, Magic, Divination Where Did Tarot Cards Come From?...
- S Style and Beauty How to Make Your Lips Fuller? Ideas and Tips for Beautiful Lips...
- S Style and Beauty How are artificial nails removed?...
- F Family and Home How to Sew Curtain Tapes: Best Tips from Professionals...
- H Horoscopes, Magic, Divination How to Cast a Love Spell on a Guy? Guide for Guys...
- F Family and Home How to Properly Use a Water Level?...
- L Legal consultation What Documents Are Required for a Russian Passport?...
- H Health and Medicine How to Treat Styes: Causes, Symptoms, and Home Remedies...
- F Family and Home Protect Your Home or Apartment from Pesky Ants...
Ответ:
a = 6, b = 0
Explanation:
The loop ran 3 times before b == 0. "while ((b != 0)" is essentially saying: 'While b is not equal to 0, do what's in my loop'. Same general thing with "&& ((a / b) >= 0)". The "&&" is specifying that there should be another loop condition, while the rest states: 'as long as a ÷ b is greater than 0, do what's in my loop'. If both of these conditions are met, the loop will run, It will continue this until the conditions are not met. Hope that helped! :)