Skip to content

Instantly share code, notes, and snippets.

@paultopia
Created August 8, 2015 21:48
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 paultopia/d360116128c787e22ce8 to your computer and use it in GitHub Desktop.
Save paultopia/d360116128c787e22ce8 to your computer and use it in GitHub Desktop.
# with list comprehension
print '\n'.join(['Fizzbuzz' if x % 15 == 0 else 'Fizz' if x % 3 == 0 else 'Buzz' if x % 5 == 0 else str(x) for x in range(input('Start: '), input('End: ') + 1, input('Step: '))])
# with lambdas and map (two versions)
print '\n'.join(map(lambda x: 'Fizzbuzz' if x % 15 == 0 else (lambda x: 'Fizz' if x % 3 == 0 else (lambda x: 'Buzz' if x % 5 == 0 else str(x))(x))(x), range(input('Start: '), input('End: ') + 1, input('Step: '))))
print '\n'.join(map(lambda x: 'Fizzbuzz' if x % 15 == 0 else 'Fizz' if x % 3 == 0 else 'Buzz' if x % 5 == 0 else str(x), range(input('Start: '), input('End: ') + 1, input('Step: '))))
# these versions sometimes work, and sometimes throw an error about being unable to convert string to int, even before user is asked for input.
# print '\n'.join(map(lambda x: 'Fizzbuzz' if x % 15 == 0 else (lambda x: 'Fizz' if x % 3 == 0 else (lambda x: 'Buzz' if x % 5 == 0 else str(x))(x))(x), range(int(raw_input('Start: ')), int(raw_input('End: ')) + 1, int(raw_input('Step: ')))))
# print '\n'.join(['Fizzbuzz' if x % 15 == 0 else 'Fizz' if x % 3 == 0 else 'Buzz' if x % 5 == 0 else str(x) for x in range(int(raw_input('Start: ')), int(raw_input('End: ')) + 1, int(raw_input('Step: ')))])
@paultopia
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment