Starting from:
$35

$29

Laboratory 1 Getting Started with Python; Simple Arithmetic Solution

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.

0. Log on to the computer using your Cougars account information.

a. username: cougarsUserName@cougars.int password: cougarsPassword

b. 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.]




2. Writing your first Python program.

a. Choose File, then Open, to open "Lab1.py"

b. Replace the text <your name goes here with your name.

c. 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.

d. 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).




3. 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.

 
print(“Hello, world”)

 
print(“Hello”, “world”)

 
print(“2” + “3”)

 
print(2 + 3)

 
print(2 * 3)

 
print(“2” * 3)




4. 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)










5. 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.




6. 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.




7. 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.)




8. 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().




9. 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.




10. Log off of the computer you are using.

More products