HOMEWORK 01: FUNCTIONS & STATEMENTS SOLVED

$24.99 $18.99

Introduction The goal of this homework is for you to allow your TAs to get to know you as well as allow you to practice and understand how to write functions and evaluate expressions. Part 1 is simply uploading a photo of your face given the specifications listed. Part 2 will consist of 7 functions…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:

Description

5/5 – (2 votes)

Introduction

The goal of this homework is for you to allow your TAs to get to know you as well as allow you to practice and understand how to write functions and evaluate expressions. Part 1 is simply uploading a photo of your face given the specifications listed. Part 2 will consist of 7 functions for you to implement. You have been given HW1.py to fill out with instructions in the docstrings. However, below you will find more detailed information to complete your assignment. Read it thoroughly before you begin. You have until Thursday, August 31st to complete this assignment.

String Formatting

A concept that will be very helpful for this homework is string formatting. The purpose of this is to allow you to manipulate statements using variables so that values can change within depending on the different outputs of the function. In order to do this, let’s use an example where I ask the user for their name, and then print it out. Try this examples out:

name = input(“What is your name?”)

print(“Your name is {}”.format(name))

num = 3.141592

print(“pi is {:.2f}”.format(num))

What is happening is that anywhere in a string, I can put {} to indicate a placeholder for a variable. After the end quotation marks, I would write .format() to the end, and inside the parenthesis will be the variables that you want to include, in the order that {} are placed in the sentence. Read this for more info: [ https://pyformat.info/ ]

HOMEWORK 01: FUNCTIONS & STATEMENTS

2

print vs. return

Distinguishing the difference between print and return is extremely important now and in the future. Print takes a python object and outputs a printed representation of it in the output window. You can think of a print statement as something for the person. Printing has no ongoing execution of a program. It doesn’t assign a value to the variable. For example, if you have this function:

def printFunc():

print(2)

In your shell, you should get this:

  • a = printFunc()

2

  • print(a)

None

However, return is used for a function when you need to save the result of the function to be used for later. By returning a value, the function is producing a value for use by the program, in particular for use in the part of the code where the function was invoked. For example, if you have this function:

def returnFunc():

return 2

In your shell, you should get this:

  • b = returnFunc()

  • print(b)

2

Read this for more info: [ http://interactivepython.org/runestone/static/pip2/Functions/Printvs.return.html ]

Part 1: Mugshot

Find a picture of yourself. Crop the picture to include just your face. (Your face must be at least 1/3 of the image.) Resize the picture to be exactly 300 pixels by 300 pixels in size. Save the picture as a JPG, using your first and last name as the file name, (e.g. Jay_Summet.jpg). Submit this picture to t-square. You may use an image editing tool you are familiar with to manipulate your mugshot picture. If you do not have a preference, we recommend using the GNU Image Manipulation Program (GIMP): http://www.gimp.org/downloads/

HOMEWORK 01: FUNCTIONS & STATEMENTS

3

Part 2: Functions

Function name (1): weight_on_mars

Parameters: N/A

Return value: N/A

Description: Write a Python program which accepts your weight on Earth and prints out your weight on Mars. Assume that the weight inputted is not negative. The weight can be

  1. Ask the user to input their weight on Earth in pounds.

  1. Your weight on Mars is 0.38 of your weight on Earth. For example, if you weight 100 pounds on Earth, you would weigh 38 pounds on Mars.

  2. Print out the answer in the format: “At a weight of 100 pounds on Earth, you would weigh

38 pounds on Mars”.

Test Cases (not an exhaustive list):

  1. >>> What is your weight on Earth (in pounds)?

150

At a weight of 150 pounds on Earth, you would weigh 57 pounds on Mars.

2. >>> What is your weight on Earth (in pounds)?

100.8

At a weight of 100.8 pounds on Earth, you would weigh 38.304 pounds on Mars.

Function name (2): volume_of_cone

Parameters: N/A

Return value: volume of the cone

Description:

Write a function that takes the radius and height from the user and calculates the volume of a cone.

  1. Get the length of the radius of the cone from the user.

  1. Get the height of the cone from the user.

  1. Calculate the volume of a cone with the radius length and height entered by the user using the following formula:

= 0 ∗ ℎ ℎ

3

    1. Return the volume of the cone rounded to three decimal places.

Hints:

  • You can round a number by using the round(number, number of decimal places) function or by using string formatting. For example, you can round 56.14523 to 56.145 by

doing round(56.14523,3). [ https://docs.python.org/3/library/functions.html#round ]

  • Importing the math module to get the value of π might be helpful. In other words, you must use the math module π. You will lose points if you hardcode 3.14.

Test Cases (not an exhaustive list):

  1. >>> a = volume_of_cone()

    • What is the length of the radius of the cone? 3

    • What is the height of the cone?

4

  • print(a) 37.699

HOMEWORK 01: FUNCTIONS & STATEMENTS

7

Grading Rubric

Mugshot: 20 points

File Named Correctly: 5 Points

Correct File Size: 10 Points

Face Recognizable: 5 Points

  • weight_on_mars: 10 points

Correct function header: 2 Points

Prints in the correct format: 3 Points

Correct Value is calculated: 5 Points

volume_of_cone: 10 points

Correct function header: 2 Points

Prints in the correct format: 3 Points

Returns the correct value: 5 Points

calculate_velocity: 10 points

Correct function header: 2 Points

Prints in the correct format: 3 Points

Correct response is calculated: 5 Points

liquid_converter: 10 points

Correct function header: 2 Points

Prints in the correct format: 3 Points

Correct response is calculated: 5 Points

calorie_counter: 15 points

Correct function header: 2 Points

Prints in the correct format: 3 Points

Correct response is calculated: 7 Points

paycheck_computation: 20 points

Correct function header: 2 Points

Prints in the correct format: 3 Points

Returns correct value: 8 Points

main: 5 points

Calls the correct function: 5 Points

Provided

The following file(s) have been provided to you. There are several, but you will only edit one of them:

  1. HW1.py

This is the file you will edit and implement. All instructions for what the methods should do are in the docstrings.

Deliverables

You must submit all of the following file(s). Please make sure the filename matches the filename(s) below. Be sure you receive the confirmation email from T-Square, and then download your uploaded files to a new folder and run them.

  1. HW1.py

  1. First_Last.jpg

Authors: Lucille Wang | Report Issues: lucillewang@gatech.edu

HOMEWORK 01: FUNCTIONS & STATEMENTS SOLVED
$24.99 $18.99