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

Marta P.
Marta P.
2,849 Points

Help me tweak this little program I built?

Hello everyone! I managed to build this little program (on my computer, not workspaces) that goes through Reddit's r/gifrecipes and prints the recipes with the ingredient you give. It works quite well, but one thing bugs me terribly.

I can't figure out how to have the program print "No __ recipes yet, I'm afraid" just when there is NO recipe that contains the keyword given by the user. I tried it all with all kinds of loops, but at the moment the closest I can get to it is having the program printing the sentence at the end of the exhaustion of the for loop.

I know the solution is close! Here is my script:

#! /usr/bin/python
import feedparser
import os
os.system('clear')


page = feedparser.parse("https://www.reddit.com/r/GifRecipes/.rss")

def gifrecipe_finder():
    os.system('clear')
    word = raw_input('\n What do you wanna cook? ')
    for i in page.entries:
        while word in i.title or word in i.link:
            print '\n'
            print ' ' + i.title
            print ' ' + i.link
            print '\n'
            break

    if word not in i.title or word in i.link:
        print '\n No {} recipes yet, I\'m afraid \n'.format(word)
        do_over()



def do_over():
    again = raw_input('\n Still hungry?(y/n) ')
    while again not in ('y', 'n'):
        again_two = raw_input('\n Sorry, didn\'t catch that.(y/n) ')
        if again_two == 'y':
            gifrecipe_finder()
        elif again_two == 'n':
                quit()
    if again == 'y':
        gifrecipe_finder()
    elif again == 'n':
            quit()





gifrecipe_finder()