View Full Version : Need help with python control structures.

10-12-2011, 10:57 PM
I'm currently taking a computer science class in my high school and right now we are working with a program called jeroo and are starting with the python language. We got through the basics and methods and now we are learning control structures. In the assignment we're doing now we have to "connect the dots". It checks to see if a flower is ahead and if there isn't it hops and plants a flower. And if there is a flower to the left or right it turns and continues checking for flowers. But my problem is we have to make it work for two different maps. I need to know if there is a way to loop a method without typing it in the main method over and over. For example:

def a(self):
while not self.isFlower(AHEAD)
Is there a way to make it check the while statement again without using the method twice? Also we have to make it stop if there is a flower to your left and right. How would I do this? Because when it gets there it will keep checking for flowers to the left or right and turning until it can hop. I know I could use
if self.isFlower(LEFT) and self.isFlower(RIGHT) to check for the flowers, but I don't know what to do to end the program. I included the assignment and my current work. I know it's sloppy but I normally neaten it up before I hand something in, and I know I have an infinite loop in the last method. And I uploaded the jeroo program on mediafire because the jeroo website is down and it exceeds the size limitations on this site.