Skip to content

Instantly share code, notes, and snippets.

@ricalanis
Created December 11, 2017 04:49
Show Gist options
  • Save ricalanis/97026b7247f32c23186fe2a3ce1c5452 to your computer and use it in GitHub Desktop.
Save ricalanis/97026b7247f32c23186fe2a3ce1c5452 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"outputByDenominator = {3: \"Crackle\", 5: \"Pop\"}"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"def printCracklePop(number):\n",
" output = \"\"\n",
" for key in outputByDenominator.keys():\n",
" if number%key == 0:\n",
" output = output + outputByDenominator[key]\n",
" if output == \"\": output = str(number)\n",
" print(output)\n",
" return output"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"Crackle\n",
"4\n",
"Pop\n",
"Crackle\n",
"7\n",
"8\n",
"Crackle\n",
"Pop\n",
"11\n",
"Crackle\n",
"13\n",
"14\n",
"CracklePop\n",
"16\n",
"17\n",
"Crackle\n",
"19\n",
"Pop\n",
"Crackle\n",
"22\n",
"23\n",
"Crackle\n",
"Pop\n",
"26\n",
"Crackle\n",
"28\n",
"29\n",
"CracklePop\n",
"31\n",
"32\n",
"Crackle\n",
"34\n",
"Pop\n",
"Crackle\n",
"37\n",
"38\n",
"Crackle\n",
"Pop\n",
"41\n",
"Crackle\n",
"43\n",
"44\n",
"CracklePop\n",
"46\n",
"47\n",
"Crackle\n",
"49\n",
"Pop\n",
"Crackle\n",
"52\n",
"53\n",
"Crackle\n",
"Pop\n",
"56\n",
"Crackle\n",
"58\n",
"59\n",
"CracklePop\n",
"61\n",
"62\n",
"Crackle\n",
"64\n",
"Pop\n",
"Crackle\n",
"67\n",
"68\n",
"Crackle\n",
"Pop\n",
"71\n",
"Crackle\n",
"73\n",
"74\n",
"CracklePop\n",
"76\n",
"77\n",
"Crackle\n",
"79\n",
"Pop\n",
"Crackle\n",
"82\n",
"83\n",
"Crackle\n",
"Pop\n",
"86\n",
"Crackle\n",
"88\n",
"89\n",
"CracklePop\n",
"91\n",
"92\n",
"Crackle\n",
"94\n",
"Pop\n",
"Crackle\n",
"97\n",
"98\n",
"Crackle\n",
"Pop\n"
]
}
],
"source": [
"outputs = [printCracklePop(_) for _ in range(1,100+1)]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment