import math from random import randrange secret_point = randrange(10000) starting_point = 50 current_point = starting_point step = 1 direction = 'up' steps_in_same_direction = 1 while True: if current_point < secret_point: if direction == 'up': steps_in_same_direction = steps_in_same_direction +1 step = int(math.exp(steps_in_same_direction)) else: step = 1 steps_in_same_direction = 1 current_point = current_point + abs(step) direction = 'up' else: if direction == 'down': steps_in_same_direction = steps_in_same_direction+1 step = step - int(math.exp(steps_in_same_direction)) else: step = 1 steps_in_same_direction = 1 current_point = current_point - abs(step) direction = 'down' print 'secret number is {}, current number is {}'.format(secret_point, current_point) if current_point == secret_point: print 'secret number is {}, found number is {}'.format(secret_point, current_point) break
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question