{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 1: With Conditionals. Test to see if a number (a) is positive. If it is positive save it in a variable called is_pos" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "a=2\n", "is_pos=True" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "#Write Code Here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 2: Make a list of numbers. Create a new list. Loop over the list and save the square of each of these numbers in the new list." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "l_1=[1,2,4]\n", "output=[1,4,16]\n", "#Write Code Here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 3: Write a function that takes three numbers as inputs and returns a*b+c. And then use this to calculate the value when the function takes 2,3,1 as an input. (The answer is 7)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "#Write Code Here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 4: Create two lists. Add both of them together." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the value of i is 0\n", "the element in the list is 5\n", "--------------\n", "the value of i is 1\n", "the element in the list is 2\n", "--------------\n", "the value of i is 2\n", "the element in the list is 7\n", "--------------\n" ] } ], "source": [ "#Here is a hint\n", "list_1=[5,2,7]\n", "for i in range(len(list_1)):#Range makes a list sort of an object. And Len is the length of the list\n", " print('the value of i is',i)\n", " print('the element in the list is',list_1[i])\n", " print('--------------')" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "#Write Code Here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 5: Write a function to convert from celsius to fahrenheit and vice versa depending on the input is_fahrenheit" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "F_in=32\n", "C_in=0\n", "C_out=(5/9)*(F_in-32) #Formula for converting from Fahrenheit to Centigrade\n", "F_out=9*C_in/5+32 #Formula for converting from Centigrade to Fahrenheit" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "def convert_temp(input_temp,is_fahrenheit):\n", " #Write Function Here\n", " return None" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## For a comprehensive set of programs: follow:\n", "https://www.programiz.com/python-programming/examples" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }