Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Gettin' CRUD-y With It View and Search Entries

which line switches next entry of dairy?

def view_entries():
    """view previous entry"""
    entries = Entry.select().order_by(Entry.timestamp.desc())

    for entry in entries:
        timestamp = entry.timestamp.strftime('%A %B %d, %Y %I:%M%p')
        print(timestamp)
        print("=" * len(timestamp))
        print(entry.content)
        print('n) for next entry')
        print('q) return to main menu')

        next_action = input("Action: [NQ] ").lower().strip()
        if next_action == 'q':
            break

menu = OrderedDict([
    ('a', add_entry),
     ('v', view_entries), 
])

if __name__ =='__main__':
    initialize()
    menu_loop()

as per my understanding print(entry.content) inside for loop should print all the entry but in this code we need to press n for next entry ?

[MOD: added ```python formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Good question! There isn’t any β€œaction” that switches to the next entry. The input loop is only looking for the q to quit. Otherwise, the for loop automatically sets entry to the next record. The illusion of choice only suggests that selecting n does something specific. The code simply ignores when an n is input.