Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with python control structures.

    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:
    Code:
    def a(self):
       while not self.isFlower(AHEAD)
          self.hop()
          self.plant()
        self.hop()
    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
    Code:
    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.
    http://www.mediafire.com/?on4rks79nhdb3h8
    Attached Files Attached Files


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •