Final Programming Practice


As a practice for the programming portion of the final, for this closed lab you not allowed to talk with other students, use the Internet, your book, previous programs, notes, etc. Any questions must be directed to Cody.

Due Date

Today, by the end of closed lab.

Part A:

Write a complete Python script that takes three numbers and reports the following:

  1. The smallest number
  2. The largest number
  3. The average of all three numbers
  4. Which two numbers are the closest together

Examples

The following are examples of correct execution (with the text in bold being the input from the user):
Please enter a number: 11.1
Please enter a number: 222.2
Please enter a number: 3333.3

The smallest number is 11.1
The largest number is 3333.3
The average is 1188.9
The two numbers that are the closest are 11.1 and 222.2
Please enter a number: 3.14159
Please enter a number: 1.41421
Please enter a number: 2.71828

The smallest number is 1.41421
The largest number is 3.14159
The average is 2.4
The two numbers that are the closest are 3.14159 and 2.71828

Submission

Submit your python script using the handin program. For handin, for this part, type the following in a terminal window exactly as it appears:
handin  pe18a  pe18a.py
To verify your submission, type the following in a terminal window:
handin  pe18a

Part B:

Write a complete Python script that requests the name of an input file, reads in its contents of the input file, and writes the lines in reverse order.

Example

Example input file (found in your home directory on your account): theLostGeneration.txt (a poem by Jonathan Reed):
I am part of a lost generation.
And I refuse to believe that
I can change the world.
I realize this may be a shock, but
"Happiness comes from within"
Is a lie, and
"Money will make me happy"
So in thirty years, I will tell my children
They are not the most important thing in my life.
My employer will know that
I have my priorities straight because
Work
Is more important than
Family
I tell you this:
Once upon a time
Families stayed together
But this will not be true in my era.
This is a quick fix society
Experts tell me
Thirty years from now, I will be celebrating the tenth anniversary of my divorce.
I do not concede that
I will live in a country of my own making.
In the future,
Environmental destruction will be the norm.
No longer can it be said that
My peers and I care about this Earth.
It will be evident that
My generation is apathetic and lethargic.
It is foolish to presume that
There is hope.
The following is an example of correct execution (with the text in bold being the input from the user):
Please enter the name of the input file: theLostGeneration.txt

There is hope.
It is foolish to presume that
My generation is apathetic and lethargic.
...
And I refuse to believe that
I am part of a lost generation.

Submission

Submit your python script using the handin program. For handin, for this part, type the following in a terminal window exactly as it appears:
handin  pe18b  pe18b.py
To verify your submission, type the following in a terminal window:
handin  pe18b