{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Python \n", "\n", "Welcome to your first assignment.\n", "\n", "**Instructions:**\n", "- You will be using Python 3.\n", "- Do not modify; write your code in the specified section.\n", "\n", "**After this assignment you will:**\n", "- Be able to use iPython Notebooks, print() and input() functions.\n", "\n", "Let's get started!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q 1 : Display your name on your screen as `My name is `.\n", "\n", "**Sample output**: `My name is John`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2020-08-02T08:00:01.120468Z", "start_time": "2020-08-02T08:00:01.115350Z" } }, "outputs": [], "source": [ "### START CODE HERE ### (≈ 1 line of code)\n", "\n", "print(\"My name is John.\")\n", "\n", "### END CODE HERE ###" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q 2 : Display your name on your screen separarted by double asterisk (\\*\\*) as `My**Name**Is**`.\n", "\n", "**Sample output**: `My**Name**Is**John`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2020-08-02T08:00:18.447086Z", "start_time": "2020-08-02T08:00:18.439073Z" } }, "outputs": [], "source": [ "### START CODE HERE ### (≈ 1 line of code)\n", "\n", "print(\"My\", \"Name\", \"is\", \"John.\", sep = '**')\n", "\n", "### END CODE HERE ###" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2020-07-30T16:15:15.958585Z", "start_time": "2020-07-30T16:15:15.953679Z" } }, "source": [ "### Q 3 : Store your name in a variable named my_name. Then print `Hello! .` to your screen.\n", "\n", "**Sample output**: `Hello! John.`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2020-08-02T08:00:34.075458Z", "start_time": "2020-08-02T08:00:34.070255Z" } }, "outputs": [], "source": [ "### START CODE HERE ### (≈ 2 line of code)\n", "\n", "my_name = 'John'\n", "print(\"Hello!\" + \" \"+ my_name + \".\")\n", "#print(\"Hello!\", my_name+\".\")\n", "\n", "### END CODE HERE ###" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Q 4 : Create three variable to store your name, age and favourite color and print them in separate lines using one print statement.\n", "\n", "**Hint**: You can pass multiple objects in print(). Also, you can write multiple logical lines in one physical line\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2020-08-02T08:15:57.827718Z", "start_time": "2020-08-02T08:15:57.822073Z" } }, "outputs": [], "source": [ "### START CODE HERE ### (≈ 2 line of code)\n", "\n", "my_name, my_age, my_color = \"John\", 42, \"Green\"\n", "print(my_name, my_age, my_color, sep = '\\n')\n", "\n", "### END CODE HERE ###" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2020-07-30T16:15:15.958585Z", "start_time": "2020-07-30T16:15:15.953679Z" } }, "source": [ "### Q 5 : Write an interactive program that takes two user input - name and age and prints to your screen:\n", "\n", "### `Hi. My name is and I'm years old.` \n", "\n", "### Also, do provide an input prompt.\n", "\n", "**Hint**: Use intput() function for each variable. Also, you can write multiple logical lines in one physical line." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### (≈ 2 line of code)\n", "\n", "name = input(\"Enter your name : \")\n", "age = input(\"Enter your age : \")\n", "\n", "#f-string\n", "print(f\"My name is {name} and I'm {age} years old.\")\n", "\n", "#format method\n", "print(\"My name is {} and I'm {} years old.\".format(name, age))\n", "### END CODE HERE ###" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2020-07-30T16:15:15.958585Z", "start_time": "2020-07-30T16:15:15.953679Z" } }, "source": [ "### Q 6 : Write a program that takes two values from the user and prints their product to the screen as :\n", "\n", "### ` The product of and is : .`\n", "\n", "**Hint**: Use intput() once to receive all user inputs and then split the input. Remember to convert inputs from strings to integers to get the product and finally some sort of string formatting to dynamically print the numbers and their product. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### (≈ 2 line of code)\n", "\n", "num1, num2 = map(int, input(\"Enter two number :\").split())\n", "print(f\"The product of {num1} and {num2} is {num1*num2}\")\n", "\n", "### END CODE HERE ###" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2020-07-30T16:15:15.958585Z", "start_time": "2020-07-30T16:15:15.953679Z" } }, "source": [ "### Q 7 : Write a interactive program that takes any word as input from the user and creates a list where each element of the list is a single letter and then prints all the letters separated by ` >>> `.\n", "\n", "**Hint**: Use list() on the input. Remember, you can unpack a sequence while printing.\n", "\n", "**Sample input**: `abcde`\n", "\n", "**Sample output**: `a >>> b >>> c >>> d >>> e`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### START CODE HERE ### (≈ 2 line of code)\n", "\n", "myString = input(\"Enter the string :\")\n", "print(*list(myString), sep = \" >>> \")\n", "\n", "### END CODE HERE ###" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2020-07-30T16:15:15.958585Z", "start_time": "2020-07-30T16:15:15.953679Z" } }, "source": [ "### Q 8 : Write a interactive program that takes a temperature recorded in Celcius and converts it to Fahrenheit scale. Finally print using string formatting:\n", "\n", "### ` degrees Fahrenheit is equal degress in Celsius scale.` \n", "\n", "**Hint**: F = (9/5)xC + 32" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2020-08-02T09:14:19.602523Z", "start_time": "2020-08-02T09:14:19.599262Z" } }, "outputs": [], "source": [ "### START CODE HERE ### (≈ 3 line of code)\n", "\n", "temp_C = float(input(\"Enter temp in Celsius :\"))\n", "temp_F = temp_C * (9/5) +32\n", "print(f\"{temp_F} degrees Fahrenheit is equal {temp_C} degress in Celsius scale.\")\n", "\n", "### END CODE HERE ###" ] } ], "metadata": { "coursera": { "course_slug": "neural-networks-deep-learning", "graded_item_id": "XHpfv", "launcher_item_id": "Zh0CU" }, "hide_input": false, "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.8.3" } }, "nbformat": 4, "nbformat_minor": 2 }