Skip to content

Instantly share code, notes, and snippets.

@pvsousalima
Last active August 29, 2015 14:12
Show Gist options
  • Save pvsousalima/18c681dad2738a81f3be to your computer and use it in GitHub Desktop.
Save pvsousalima/18c681dad2738a81f3be to your computer and use it in GitHub Desktop.
Google's code resolutions
'''Given a function which produces a random integer in the range 1 to 5,
write a function which produces a random integer in the range 1 to 7.'''
import random
# Produces a random integer in the range 1 to 5
def random_int15():
return random.choice(range(1,6))
# Produces a random integer in the range 1 to 7 using the previous function
def random_int17():
choice = random_int15()
return (random.choice(range(0,3))+choice) if (choice == 5) else choice
# Execute choices list
choices = []
for i in range(10):
choices.append(random_int17())
print(choices)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment