You are on page 1of 9

{

"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Jenny_Maharjan_FODS_Assignment_I.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "uiK0fGWOnXcQ"
},
"source": [
"Book :- \n",
"Author :- Mark Lutz \n",
"1. Learning Python 5th Edition O'Reilly\n",
"2.Python Cookbook David Beazley O'Reilly \n",
"\n",
"Link:- \n",
"1. http://www.cs.uni.edu/~fienup/cs051f10/lectures/\n",
"2. https://github.com/MrAlex6204/Books/blob/master/Learning%20Python%2C
%205th%20Edition.pdf\n",
"3. https://github.com/tomarraj008/data_books/blob/master/Python%20Cookbook
%2C%203rd%20Edition.pdf\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "g5RW89-P01bg"
},
"source": [
"First Week Assignment \n",
"\n",
"Test Your Knowledge: Quiz \n",
"\n",
"1. What are the six main reasons that people choose to use Python?\n",
"2. Name four notable companies or organizations using Python today.\n",
"3. Why might you not want to use Python in an application?\n",
"4. What can you do with Python?\n",
"5. What’s the significance of the Python import this statement?\n",
"6. Why does “spam” show up in so many Python examples in books and on the
Web?\n",
"7. What is your favorite color?\n",
"\n",
"\n",
"Test Your Knowledge: Quiz\n",
"1. What is the Python interpreter?\n",
"2. What is source code?\n",
"3. What is byte code?\n",
"4. What is the PVM?\n",
"5. Name two or more variations on Python’s standard execution model.\n",
"6. How are CPython, Jython, and IronPython different?\n",
"7. What are Stackless and PyPy?\n",
"\n",
"Test Your Knowledge: Quiz\n",
"1. How can you start an interactive interpreter session?\n",
"2. Where do you type a system command line to launch a script file?\n",
"3. Name four or more ways to run the code saved in a script file.\n",
"4. Name two pitfalls related to clicking file icons on Windows.\n",
"5. Why might you need to reload a module?\n",
"6. How do you run a script from within IDLE?\n",
"7. Name two pitfalls related to using IDLE.\n",
"8. What is a namespace, and how does it relate to module files?\n",
"\n",
"\n",
"Test Your Knowledge: Quiz\n",
"\n",
"1. Name four of Python’s core data types.\n",
"2. Why are they called “core” data types?\n",
"3. What does “immutable” mean, and which three of Python’s core types are
considered immutable?\n",
"4. What does “sequence” mean, and which three types fall into that
category?\n",
"5. What does “mapping” mean, and which core type is a mapping?\n",
"6. What is “polymorphism,” and why should you care?\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6kafgQs5S8WY"
},
"source": [
"**Projects:-**<br>\n",
"1. Open a Python shell, enter the following expressions, and observe the
results:<br>\n",
"a. 8<br>\n",
"b. 8 * 2<br>\n",
"c. 8 ** 2<br>\n",
"d. 8/12<br>\n",
"e. 8 // 12<br>\n",
"f. 8/0"
]
},
{
"cell_type": "code",
"metadata": {
"id": "M0vvPpdkTWOZ"
},
"source": [
"8"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "a7SbtkU6WCF8"
},
"source": [
"8*2"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "8LQ67xU1WD87"
},
"source": [
"8**2"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "r_TbnDA_WFvd"
},
"source": [
"8/12"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "w6EA-6d9WIgs"
},
"source": [
"8//12"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "5JSh2oUNWJt3"
},
"source": [
"8/0"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "ySRylLzXTg4L"
},
"source": [
"2. Write a Python program that prints (displays) your name, address, and
telephone number"
]
},
{
"cell_type": "code",
"metadata": {
"id": "IC-e8BmAUMex"
},
"source": [
"name=\"jma\"\n",
"address=\"home\"\n",
"telephone=1234567890\n",
"print(name)\n",
"print(address)\n",
"print(telephone)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "H-t99QCLUNap"
},
"source": [
"3. Evaluate the following code at a shell prompt: print(\"Your name is\",
name). Then assign name an appropriate value, and evaluate the statement again."
]
},
{
"cell_type": "code",
"metadata": {
"id": "dXcXgJUSUhwR"
},
"source": [
"name=input(\"Enter name =\")\n",
"print(\"Your name is\",name)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "qjgWML-AUi-v"
},
"source": [
"4. Write and test a program that accepts the user's name(as text) and
age(as a number) as input. The program should output a sentense containing the
user's name and age."
]
},
{
"cell_type": "code",
"metadata": {
"id": "a3yt3ND1WkF0"
},
"source": [
"name=input(\"Enter your name =\")\n",
"age=int(input(\"Enter your age =\"))\n",
"print(\"Your name is\",(name),\"and your age is\",(age))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Fw-qO1W9WlGW"
},
"source": [
"5. Write and test a program that computes the area of a circle. This
program should request a number representing a radius as input from the user. It
should use the formula 3.14*radius**2 to compute the area and then output this
result suitably labeled."
]
},
{
"cell_type": "code",
"metadata": {
"id": "PwqzW8U-W8fB"
},
"source": [
"radius=float(input(\"Enter radius =\"))\n",
"area=3.14*(radius**2)\n",
"print(\"Area of a circle =\",area)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "roHMT8eHXDFg"
},
"source": [
"6. Enter an input statement using the input function at the shll prompt.
When the prompt asks you for input, enter a number. Then, attempt to add 1 to that
number, observe the results and explain what happened."
]
},
{
"cell_type": "code",
"metadata": {
"id": "Y9danKsrXXLJ"
},
"source": [
"a=int(input(\"Enter a number =\"))\n",
"a=a+1\n",
"print(a)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "-ud9b4rIXdyO"
},
"source": [
"7. Enter the expression help() at the shell prompt. Follow the
instructions to browse the topics and modules."
]
},
{
"cell_type": "code",
"metadata": {
"id": "Q6DP_R5hXmmS"
},
"source": [
"help()"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Mh0jLr5HYCzo"
},
"source": [
"8. The tax calculator program of the case study outputs a floating-point
number that might show more than two digits of precision. Use the round function to
modify the program to display at most two digits of precision in the output
number."
]
},
{
"cell_type": "code",
"metadata": {
"id": "6JN4PaojYEK4"
},
"source": [
"tax=float(input(\"Enter tax amount =\"))\n",
"print(round(tax, 2))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "SeHW1j9kYF8Q"
},
"source": [
"9. You can calculate the surface area of a cube if you know the length of
an edge. Write a program that takes the length of an edge(an integer) as input and
prints the cube's surface area as output."
]
},
{
"cell_type": "code",
"metadata": {
"id": "otcAXgxxYkx6"
},
"source": [
"a=int(input(\"Enter length =\"))\n",
"area=6*a**2\n",
"print(\"Surface area of a cube=\",area)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "O3379lCKYlcr"
},
"source": [
"10.Five Star Retro Video rents VHS tapes and DVDs to the same connoisseurs
who like to buy LP record albums. The store rents new videos for $3.00 a night, and
oldies for $2.00 a night.\n",
"\n",
"Write a program that the clerks at Five Star Retro Video can use to
calculate the total charge for a customer’s video rentals.\n",
"\n",
"The program should prompt the user for the number of each type of video
and output the total cost."
]
},
{
"cell_type": "code",
"metadata": {
"id": "kKoIAmUpY4dY"
},
"source": [
"a=int(input(\"Enter number of new videos =\"))\n",
"b=int(input(\"Enter number of old videos =\"))\n",
"new=a*3\n",
"old=a*2\n",
"print(\"Total charge =\",new+old)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "oBQWzZuoY9dH"
},
"source": [
"11. Write a program that takes the radius of a sphere(a floating point
number) as input and then outputs the sphere's diameter, circumference, surface
area and volume."
]
},
{
"cell_type": "code",
"metadata": {
"id": "MNAlLLYrbatP"
},
"source": [
"radius=float(input(\"Entere radius = \"))\n",
"d=2*radius\n",
"c=2*3.14*radius\n",
"s=4*3.14*(radius**2)\n",
"v=(4/3)*3.14*(radius**3)\n",
"print(\"Diameter of sphere is\",d)\n",
"print(\"circumference of sphere is\",c)\n",
"print(\"Suface area of sphere is\",s)\n",
"print(\"Volume of sphere is\",v)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "zOx3W9G8bb_2"
},
"source": [
"12. Instructions An object's momentum is its mass multiplied by its
velocity. Write a program that accepts an object's mass (in kilograms) and velocity
(in meters per second) as inputs, and then outputs its momentum."
]
},
{
"cell_type": "code",
"metadata": {
"id": "hlYAuUajdI0X"
},
"source": [
"mass=int(input(\"Enter mass = \"))\n",
"velocity=int(input(\"Enter velocity = \"))\n",
"m=mass*velocity\n",
"print(\"Momentum = \",m)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "jU4yPCcrdf0D"
},
"source": [
"13. The kinetic energy of a moving object is given by the formula KE =
½mv2 where m is the object’s mass and v is its velocity.\n",
"\n",
"Modify the program you created in Project 5 so that it prints the object’s
kinetic energy as well as its momentum."
]
},
{
"cell_type": "code",
"metadata": {
"id": "ocVu-KGkd9lN"
},
"source": [
"mass=int(input(\"Enter mass = \"))\n",
"velocity=int(input(\"Enter velocity = \"))\n",
"m=mass*velocity**2\n",
"k=1/2*mass*velocity\n",
"print(\"Momentum = \",m)\n",
"print(\"Kinetic energy = \",k)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "KGUdbd0Od-TE"
},
"source": [
"14. An employee’s total weekly pay equals the hourly wage multiplied by
the total number of regular hours plus any overtime pay. Overtime pay equals the
total overtime hours multiplied by 1.5 times the hourly wage. Write a program that
takes as inputs the hourly wage, total regular hours, and total overtime hours and
displays an employee’s total weekly pay."
]
},
{
"cell_type": "code",
"metadata": {
"id": "d4lYL0jFekM1"
},
"source": [
"wage=int(input(\"Enter hourly wage = \"))\n",
"hour=int(input(\"Enter total regular hours = \"))\n",
"overtime=int(input(\"Enter overtime hours = \"))\n",
"pay= wage*hour+overtime*(hour*1.5)\n",
"print(\"Total week pay = \",pay)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "6KBqGepcfGWI"
},
"source": [
""
]
}
]
}

You might also like