<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 The focus of this notebook is refactoring a loop that
- gets user input
- quits if that input matches some sentinel value
- processes the user input
The interesting part starts around cell #4.
Step1:  Below is a typical loop for
- getting user input
- quitting the loop if the user enters a special value
- processing the input
Step2:  It works as shown below.
Step3:  Below is a different way of writing that loop.
How would you apply it to loop at the bottom of
2016-04/2016-Apr-Gutenberg.py?
Step4:  It can be reduced to a generator expression.
Step5:  2017-10-06 More thoughts about partial(input, prompt) and alternatives to it.
<ASSISTANT_TASK:>
Python Code:
from functools import partial
def convert(s):
    converters = (int, float)
    
    for converter in converters:
        try:
            value = converter(s)
        except ValueError:
            pass
        else:
            return value
        
    return s
def process_input(s):
    value = convert(s)
    print('%r becomes %r' % (s, value))
Explanation: The focus of this notebook is refactoring a loop that
- gets user input
- quits if that input matches some sentinel value
- processes the user input
The interesting part starts around cell #4.
End of explanation
def main():
    prompt = 'gimme: '
    while True:
        s = input(prompt)
        if s == 'quit':
            break
        process_input(s)
Explanation: Below is a typical loop for
- getting user input
- quitting the loop if the user enters a special value
- processing the input
End of explanation
main()
Explanation: It works as shown below.
End of explanation
def main():
    prompt = 'gimme: '
    for s in iter(partial(input, prompt), 'quit'):
        process_input(s)
main()
Explanation: Below is a different way of writing that loop.
How would you apply it to loop at the bottom of
2016-04/2016-Apr-Gutenberg.py?
End of explanation
prompt = 'gimme: '
get_values = (convert(s) for s in iter(partial(input, prompt), 'quit'))
for value in get_values:
    print(value)
Explanation: It can be reduced to a generator expression.
End of explanation
prompt = 'gimme: '
def get_input():
    return input(prompt)
def main():
    for s in iter(get_input, 'quit'):
        process_input(s)
main()
def main():
    prompt = 'gimme: '
    for s in iter(lambda : input(prompt), 'quit'):
        process_input(s)
main()
def my_partial(function, *args, **kwargs):
    def helper():
        return function(*args, **kwargs)
    return helper
def main():
    prompt = 'gimme: '
    for s in iter(my_partial(input, prompt), 'quit'):
        process_input(s)
main()
Explanation: 2017-10-06 More thoughts about partial(input, prompt) and alternatives to it.
End of explanation
<END_TASK>