After the lab, you should know how to
lab1
in your
labs
directory. Your programs and the
output for this lab will all be saved in
the lab1
directory.area.py
from
the /home/courses/cs111/handouts/lab1/
into
your lab1
directory.mv
command. Move the
area.py
file into the
file lab1.8.py
using
the mv
command in
the lab1
directory:
mv area.py lab1.8.py
lab1.8.py
) in the directory.We'll practice writing several Python programs, each in their own text file. Name the files lab1.1.py through lab1.8.py.
Your programs will be graded on correctness, style, and how well you tested them. Make sure you adhere to the good development and testing practices we discussed in class, use good variable names
After you've developed a correct solution to each program, close the
IDLE "shell" and reopen it by running the program again (using F5),
demonstrate that the program works using several good test
cases, and save the output to a file
named lab1.x.out
, where x is the problem
number.
i
, j
,
and result
) to calculate and display result = i² +
3j - 5 for the case where i=7 and j=2. Your code will not look
exactly like this formula. Display the result and verify that it
is correct. Put the answer/output in a comment.i
to i21
. Be sure to change the name everywhere the
variable is used. Execute it to show it works. 21i
. What error message do you get? Record in
comments the error message. Revert your program back to the
correct variable name.You only need to save the output from executing the final version of your program.
Output should look similar to
525600 minutes, 525600 moments so dear. 525600 minutes - how do you measure, measure a year?
This program determines your birth year given your age and current year Enter your age: 20 Enter the current year: 2006 You were either born in 1986 or 1985
i
to 9, j
to 2, x
to 9.0 and
y
to 2.0. result
is the fifth variable and
will hold the result of various arithmetic expressions (see below).
Write a series of six pairs of assignment and print statements in
one program as follows:
result
to i/j; display the result result
to j/i; display the result result
to x/y; display the result result
to y/x; display the result result
to i/y; display the result result
to float(i)/j; display the result
Partial (pretty) Output (sans the result variable!):
i = 9 j = 2 x = 9.0 y = 2.0 i/j = ... j/i = ... ...
Your output does not need to match the above exactly. I just want to see pretty output.
Henderson stole 1406 bases and was caught 335 times. Lou Brock is second with 938 stolen bases and 307 caught stealing.
Calculate and display Henderson's and Brock's successful base stealing percentages. (Hint: Divide the number of bases successfully stolen by the number of attempts.) Then, display the difference in their percentages.
Output should look similar to:
This program prints the Celsius temperature given a Fahrenheit temperature. Enter a Fahrenheit temperature: 70 70 degrees F is 21.111111111111111 degrees C
Note: The output is not very pretty yet. We'll learn how to format the output more nicely soon.
Note: When you demonstrate this program, especially think about what are good test cases for this program. What answers do you know?
Example output (with fake numbers--I'm not showing an equation):
Enter a: 12 Enter b: 34 Enter c: 5 The result of <print out your equation here> is 51. The result of <print out your equation with parentheses here> is 15.
area.py
program
(which you renamed lab1.8.py
earlier this
lab) to compute the area of a triangle. (How do you compute
the area of a triangle? How could you figure that out if you don't
know it?)
lab1
directory into
the turnin
directory. (Review
the UNIX handout if you don't remember how
to do that.)
printLab.sh
command.
printLab.sh <labdirpath>
labs
directory. This command should create the file lab1.ps
gv lab1.ps
&
lpr
command
introduced in the first lab.
lpr -P<printername> <filetoprint.ps>
Labs are due at the beginning of Friday's class. You should hand
in the printed copy at the beginning of class, and the electronic
version should be in the turnin
directory before 1:20
p.m. on Friday.
Ask well before the deadline if you need help turning in your assignment!