Question: Please download the following python file. Open it in Jupyter. Then follow the instruction, answer all the questions, and submit it to D2L. Assignment 2

Please download the following python file. Open it in Jupyter. Then follow the instruction, answer all the questions, and submit it to D2L. Assignment 2 Python file: 423_HW2_Variables.ipynb

********Given python File************

{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# HW2: Variables" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this assingment, we will practice variables and data types of Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Q1. Different data types (1.5 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Provide one example of each of the following data types:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# integer number: ", "a =" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Float number: ", "b = " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Complex number: ", "c = " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Booleans ", "d = " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# string ", "e =" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Q2. String data types: (1.5 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fill ____ pieces below to have correct values for lower_cased, stripped and stripped_lower_case variables." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "original = ' PYTHON IS COOL! ' ", "length_of_the_text = _____ # (1) show the lengeth of the string. ", "lower_cased = original._____ # (2) convert the string to the lower case string. ", "stripped = lower_cased._____ # (3) remove the space from both side. ", "stripped_lower_cased = original._____._____ #apply 2 & 3 at the same time" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Q3. Numbers and Creating Formulas: (2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write the following mathematical formula in Python: ", " ", "\\begin{align} ", "result & = 6a^3 - \\frac{8 b^2}{4c} + 11\\\\ ", "\\end{align}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Assume a = 2, b = 3, c = 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your formula here: make sure to use enough paranthesis in your equation. ", "a,b,c = 2, 3, 2 ", "result = " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Q4. `+` and `*` in numbers & string data types (2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Consider the following variables." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a, b = 2 , 5 ", "c, d = 'a','b'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Which of the following statements are correct and which ones are inccorrect? why?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 4.1. Is this a correct operation? why? What is the measing of this opeation? ", "a + b" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 4.2. Is this a correct operation? What is the measing of this opeation? ", "c + d" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 4.3. Is this a correct operation? why? What is the measing of this opeation? ", "a * b" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 4.4. Is this a correct operation? why? What is the measing of this opeation? ", "c * d" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 4.5. Is this a correct operation? why? What is the measing of this opeation? ", "a * d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Q5. (2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fill the blanks in the following cell based on the instructions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "message = 'Hello everybody!' ", "message._______ # sperate the text based on the space character. ", "print(message[ : ]) # print only Hello. ", "New_message= message.________ # replace ! with the red heart emojy. ", "# Simply replace '!' with '\\u2764\\ufe0f' ", "print(New_message)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Q6. (1 point)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The purpose of this question is convertin one data type to another." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a, b, c = '2','4', '6' ", "d = a + b + c ", "e = ? (d) # convert d into an integer number. ", "print(?(e)) # check data type of e ", "f = ? (d) # convert d into a floting number. ", "print(?(f)) # check data type of f ", "print(e ? f) # check whether e and f have the same data type ", "g = ? (d) + a # convert d into string." ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!