Skip to content

Instantly share code, notes, and snippets.

@jeffthemaximum
Created January 15, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffthemaximum/eba1b8a2293347a0ef5e to your computer and use it in GitHub Desktop.
Save jeffthemaximum/eba1b8a2293347a0ef5e to your computer and use it in GitHub Desktop.

Example before jeff:

Objective 1

  • Write a for loop that will take in a number
  • When the loop is called it will iterate forward towards that number and print all the values in between to the console
  • Write another loop that will do the same thing but iterate backwards from that number to zero

Example after jeff:

Challenge

  • Write a for loop that will take in a number.
  • When the loop is called it will iterate from 0 forward towards that number and print all the values in between to the terminal.
  • Write another loop that will do the same thing but iterate backwards from that number to zero.

For example, if we have the following starter code:

def my_loop(x):
    # write your code here
    # you'll have to delete "pass"
    pass

You'll write a loop with the my_loop function that will iterate from 0 to x and print out all values in between. For example:

[input]
my_loop(10)

[output]
1
2
3
4
5
6
7
8
9

In the next part, you'll write a function that will do the opposite. That is, you'll write the my_reverse_loop function that will contain a loop that will iterate from x to 0 and print out all the values in between. For example:

[input]
my_reverse_loop(5)

[output]
4
3
2
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment