CSC 15 Lab 3 9/17/07 Due 9/24 Part I: Part II of the assignment asks you to animate the stick figure you drew in lab2. Download the template danim.py from the class homepage. Right now it animates a diamond. You are to animate your stick figure. During the animation sequence, you need to: 1. Change the size of the figure to both smaller and larger 2. Change the position of the figure by changing the x,y coordinates. 3. Make the arms repeatedly go up-straight-down so it appears to be flying. This part may require you to use if and if-else statements. Demonstrate your program to the professor when you're done. part Ib: Important Linux commands. When running programs that draw graphics, please do not move the window while the program is running. If all goes well the program should stop when the mydraw function finishes. But sometimes you may want to stop it in the middle. For this, the best thing to do is the following: At the terminal prompt where you ran the program, type Control-Z. You'll see a message such as [5]+ Stopped python danim.py This program is now a zombie. A zombie is a program that should be dead but is not. You need to kill it with the following command: kill -9 %5 The "5" needs to match the number in the message above. Don't leave zombies around. At the command prompt, type the word "jobs". This shows all the programs at their current status are were started from the terminal window. You can kill them with the same command. ------------------------------------------------------------------------ Part II: This part of the assignment allows you to practice using the if-else construct. It also teaches you to think about programs in a structural way. You are to write a program that asks the user a series of questions in order to guess what kind of animal the user is talking about. The user can answer the questions with either True or False (1 or 0 can also be used) Here's a sample output of what the program might look like: Computer: Is it a mammal? True Computer: Does it walk on four legs? True Computer: Does it prey on other animals? True Computer: According to my database, your animal is likely a tiger. ---- Of course, more questions would be needed to really pin the answer down to a tiger. Your program needs to ask enough questions to distinguish between the following animals: tiger, horse, rabbit, shark, bass, turtle, snake, chicken, hawk Note the above line of questions was enough to exclude all other possibilites except tiger. You should draw a species tree to determine what and how many questions you need to ask. * If the answers do not match any of the animals in your database, you are to output a message indicating so: Computer: I'm sorry, I've no information on such an animal *** Important rule: each question can only ask a single trait, i.e, you can not ask "is it a tiger" directly - that would be cheating! --- Your program will consist of a number of if-else statements nested within if-else statments. Note that commenting is very important, in addition to the indentation, to clarify the structure of the program. When writing if and if-else statements involving more than one or two lines of code, you MUST comment the end of each logical block of code. *** I WILL NOT HELP YOU DEBUG UNCOMMENTED CODE *** Here's something to get you started with: # Variables to use: # mammal, fly, ... print "Think of an animal among tiger, horse, rabbit, shark, bass, turtle, snake, chicken, hawk" mammal = input("Is it a mammal? ") if (mammal == True): # ask next question based on answer: fly = input("can it fly> ") if (fly): # next question based on a mammal that can fly else: # next question based on a mammal that cannot fly # end mammal else: # not a mammal, next question ... ------ After you're finished with this part, put a while loop around your entire code so that the program will execute repeatedly: again = True # variable to indicate if user wants to play again while (again) # code for determining animal, excluding variable declarations again = input("go again? ") # end while ------------------------------------- What to turn in: 1. Write up on paper, including "decision tree" 2. Source code. All variables used must be commented. Each enclosed {} segment should include comments as to its purpose (as in above example) 3. two sets of output -------------------------------------