Last active
January 6, 2016 19:34
-
-
Save AnnaMag/9bf5170fd966459df50b to your computer and use it in GitHub Desktop.
Printing numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
""" | |
Toy code for a very special application:) | |
Write a program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle | |
instead of the number. If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop. | |
""" | |
def print_crackle_pop(max_no): | |
x = range(1, max_no + 1) | |
return ['CracklePop' if (i % 3 == 0 and i % 5 == 0) else 'Crackle' if not (i % 3) else 'Pop' if not (i % 5) else i for i in x] | |
# input an integer number is the maximum number we want to print | |
print print_crackle_pop(5) # from 1 to 5, both inclusive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment