{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Calculate the sum of dict values\n", "Calculate the sum of the values in `magic_dict` by taking only into account numeric values. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": false }, "outputs": [], "source": [ "magic_dict = dict(val1=44, val2='secret value', val3=55.0, val4=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your implementation\n", "sum_of_values = 0 # TODO " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": false }, "outputs": [], "source": [ "assert sum_of_values == 100" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. Create a list of strings based on a list of numbers\n", "The rules:\n", "* If the number is a multiple of five and odd, the string should be `'five odd'`\n", "* If the number is a multiple of five and even, the string should be `'five even'`\n", "* If the number is odd, the string is `'odd'`\n", "* If the number is even, the string is `'even'`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": false }, "outputs": [], "source": [ "numbers = [1, 3, 4, 6, 81, 80, 100, 95]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your implementation\n", "my_list = [] # TODO" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": false }, "outputs": [], "source": [ "assert my_list == ['odd', 'odd', 'even', 'even', 'odd', 'five even', 'five even', 'five odd']" ] } ], "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.5.4" } }, "nbformat": 4, "nbformat_minor": 2 }