Home Practicum 1 Practicum 2 Practicum 3 Practicum 4 Practicum 5 Practicum 6 Practicum 7 Practicum 8 Practicum 9 Practicum 10

Welcome to DS2000 CS Practicum 4!

Since there was no lecture this week, we're going to just practice more of the skills necessary to complete your homework 3:
  1. while loops
  2. conditional statements (if condition:)
  3. taking user input and making sure it's sane


Before we get to the actual exercise, a few reminders from last week that will help you understand your problems

Ex0: complete the extra challenge from last week

If you already did the extra challenge, please proceed to exercise 1.

Your code from exercise 5 last week should have two turtles racing to the finish point. Change it so now turtle1 chases turtle2, while turtle2 tries to run away. Your end condition will be that the distance between the two turtles is less than 5 or the turtle that's running away runs off screen (the screen spans from -400 to 400 on the x axis and from -300 to 300 on the y axis). Here are some pointers to get you started:

Ex1: taking user input

Extend your main function so that before the main loop starts, your program asks the user for the starting positions of the turtles and their speed. Now, rather than starting your turtles at the predefined positions, start them where the user wants them at the speed that the user put in. Extra points: if the user doesn't enter any number but just presses Enter, use default, CONSTANT values.

Ex2: ending the game

Create a gameover(turtle1, turtle2) function. It takes the two turtles as input, and it returns True if they are within 5 from each or if the running turtle went off screen. Call this function as your condition of the main while loop.
def main():
	# ask the user for starting positions and speed
	# create the turtles

	while not gameover(turtle1, turtle2):
		# your gameplay
Note that there is a not negation operator before gameover. The expression of while not gameover(turtle1, turtle2): means "while the game is not over do the following".