Python raw_input and conditions I have a very simple code that allows me to keep track of what the user inserts in a raw_input.

The kind of controls I check are if the user inserts "f" the program is finished or if the user inserts nothing, the program keeps on running remembering all the inputs the user has inserted.

It works but I think it's very ugly and rudimental.

I would love to get suggestions from experts so I can learn how to handle correctly simple tasks.

Here's the little code:

#!/usr/bin/python
import os
good_receipts = []
done = False
inserted_text = ''
while not done:
    # This function is os dependent and will work only if you use linux
    os.system('clear')
    inserted_text = raw_input("Insert receipt number (if you finished insert 'f'): ").upper()
    if inserted_text and inserted_text != 'F':
        good_receipts.append(inserted_text)
    while not inserted_text == 'F':
        # This function is os dependent and will work only if you use linux
        os.system('clear')
        if good_receipts:
            print "Here's your receipts:"
            print good_receipts
        if not good_receipts:
            print "You didn't enter a single receipt..."
        inserted_text = raw_input("Insert receipt number (if you finished insert 'f'): ").upper()
        if inserted_text and inserted_text != 'F':
            good_receipts.append(inserted_text)
    done = True
# This function is os dependent and will work only if you use linux
os.system('clear')
print "You did a great job, here's your receipts:"
print good_receipts
Here is what I came up with:

#!/usr/bin python
from os import system as sys

def GetReceipt():
    prompt = "Insert receipt number (if you finished insert 'f'): "
    inserted_text = ''
    while True:
        sys('clear')
        inserted_text = raw_input(prompt).upper()
        if inserted_text == 'F': break
        yield inserted_text


def final(receipt):
    sys('clear')
    print ["You did a great job, here's your receipts:\n"+' '.join(receipt), 
        "You did not enter a single receipt..."][len(receipt) == 0]

if __name__ == '__main__':
    valid_receipts = [ f for f in GetReceipt() ]
    final(valid_receipts)