Advertisement
here2share

# up_down.py

Mar 4th, 2021
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # up_down.py
  2.  
  3. def up_down(lowest_value, highest_value, step=1, current='void'):
  4.     if current == 'void':
  5.         current = lowest_value
  6.     while True: # Begin infinite loop
  7.         yield current
  8.         current += step
  9.         if current <= lowest_value or current >= highest_value:
  10.             step *= -1 # Turn around when either limit is hit
  11.            
  12. test = up_down(-5, 10)
  13. count = 0
  14. for j in test:
  15.     print(j) # for demonstration purposes
  16.     count += 1
  17.     if count >= 50: # your ending condition here
  18.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement