Computer Science 220L Laboratory 1 – Getting Started with Python; Simple Arithmetic

$25.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (3 votes)

Learning Objectives:

  1. Understand the editing and execution phases of a computer program.
  2. Be able to execute a Python program using the IDLE integrated development environment (IDE)
  3. Interact with simple Python programs that produce output and do arithmetic.
  4. Enter new programs using the IDLE editor.

 

Directed Activities:  After each activity, test your code to make certain it works properly then demonstrate your work for an instructor.

  1. Log on to the computer using your Cougars account information.
  2. username: cougarsUserName@cougars.int password: cougarsPassword
  3. Create a folder named “Lab01” on the Desktop.

 

  1. Open your OAKS account for this course.

Under Dropbox in the Lab 1 folder you will see two files. Create a folder (Lab01) on your desktop or documents folder and download all of the files from dropbox into this folder.  [There is no guarantee that the work will remain on the system from week-to-week.]

 

  1. Writing your first Python program.
  2. Choose File, then Open, to open “Lab1.py”
  3. Replace the text <your name goes here> with your name.
  4. To execute the program, from the Run menu select Run module. Or simply press the F5 key. (This loads the file into memory.) Then type main() and press enter, to execute the function.
  5. Go back to the editor window. Add a statement so that the code outputs “I look forward to learning to control this computer through programming!” Save by pressing Control-S. Execute your program, following instructions from part (c).

 

  1. What’s output?

Add the following print statements to your main() function.  Execute the function and see the printed results.  Be able to explain these.

  1. print(“Hello, world”)
  2. print(“Hello”, “world”)
  3. print(“2” + “3”)
  4. print(2 + 3)
  5. print(2 * 3)
  6. print(“2” * 3)

 

  1. Enter a new program using the editor.

Just to remind you below is the calcRectArea() function from class.  Add this function to the Lab1.py file.

 

## This function calculates the area of a rectangle

def calcRectArea():

print(“Calculates the area of a rectangle.”)

length = eval(input(“Enter the length: “))

width = eval(input(“Enter the width: “))

area = length * width

print (“Area =”, area)

 

 

 

  1. Do it yourself, user input.

Add another function called calcCylinderVolume() to your file.  This function should calculate the volume of a right cylinder (πr2h).  The user of the program will provide the radius and height of the box.  Test your function to make sure it works properly.

 

  1. Shooting percentage.

The players on the basketball team want to know their shooting percentages. Write a function, shootingPercentage(), that asks for a player’s total shots and shots made, and that computes and displays the shooting percentage.

 

  1. Coffee shop.

Write a function, coffee(), to compute the cost of shipping a coffee order. Coffee costs $10.50 per pound; shipping costs $0.86 per pound; and there is a fixed cost of $1.50 per order for overhead.  Ask the user for the number of pounds of coffee purchased then display the total cost.  (For example, 2 pounds of coffee costs $24.22.)

 

  1. Kilometers to miles.

John is planning a trip to Europe later this fall.  While there, he will rent a car and drive throughout the area.  He is trying to analyze the number of miles he will travel in order to help him budget for his gasoline use.  Being a good friend of John’s, you have agreed to write a conversion program for him that will allow him to input the number of kilometers he travels and will output the number of miles.

(1 mile = 1.61 kilometers.) Call the function kilometersToMiles().

 

  1. Upload the files to OAKS under the Assignments section:

Check list:

Lab1.py _______

 

Remove from the desktop any files and folders you created. Then, empty your recycle bin. Log out of your Cougars account.

 

  1. Log off of the computer you are using.