-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR addresses multiple issues with if-pressed not working with other code structures, e.g. list access, in/not in operator, for cycle. The major technical change in this PR that list access instances are no longer stored and treated as variables in the lookup. Consider the program: `animals is cat, dog\nprint animals at 1`. Before, the lookup table would hold two variables: `animals` and `animals[int(1)-1]`. Now, it will only hold the variable `animals` and registers the occurrence of `animals[int(1)-1]` as variable access. Fixes #5955 **How to test** The following code snippets should work. Use them as starting points for further testing. ``` # level 9 points = 0 letters = a, b, c, d, e repeat 10 times letter = letters at random print 'Press the letter ' letter if letter is pressed print 'great' points = points + 1 else print 'oops wrong letter' points = points - 2 print points ``` ``` # level 17 # Make 2 lists colors = ['red','yellow','green','blue'] simon_sequence = [] player_sequence = [] # Create a function that adds a color define add_random_color: color = colors[random] add color to simon_sequence # Create a function that shows the simon_sequence define show_simon_sequence with level: for i in range 1 to level: print simon_sequence[i] sleep 1 clear # Create a function that creates the player_sequence define get_answer with level: for i in range 1 to level: print 'What is color number ' i '?' print 'press (r)ed, (y)ellow, (g)reen or (b)lue' if r is pressed: answer = 'red' elif y is pressed: answer = 'yellow' elif g is pressed: answer = 'green' elif b is pressed: answer = 'blue' else: print 'press (r)ed, (y)ellow, (g)reen or (b)lue' add answer to player_sequence # Set up level = 1 game_over = False print 'Welcome to Simon Says!' sleep 1 clear # The game while game_over == False: print 'this is level ' level sleep 1 clear player_sequence = [] call add_random_color call show_simon_sequence with level call get_answer with level if player_sequence == simon_sequence: print 'Well done!' sleep 1 level = level + 1 else: print 'Helaas pindakaas' game_over = True ```
- Loading branch information
1 parent
5308864
commit c339053
Showing
7 changed files
with
1,338 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.