CSC111 Homework 4

From dftwiki3
Jump to: navigation, search

This assignment can be done in pair-programming mode, or individually. It is due on 2/25/2010 at midnight



Problem #1

Write a Python program called hw4a.py which computes the final grade for a student taking CSC111. The best way to understand how your program will work is to follow the example below where the user input is underlined:

python hw4a.py 
Welcome to the 111c grading center
==================================

How many homework assignments this semester? 10
What is the overall weight of the homework assignments? 0.60
What is the weight of the midterm exam? 0.20
What is the weight of the final exam?   0.20

Please enter the grades for the homework assignments, one per line,

4
4
3.3
3.7
4
3
3.3
3.7
4
4

Please enter the grades for the midterm, followed by the final, also one per line.

3.3
3.7


Number of assignments:     10
grade of lowest assignment                : 3
Sum of all the assignment (without lowest): 34.0
Average assignment grade (without lowest) : 3.77777777778

Weighted total average  = 3.66666666667

(It is possible that when you run your program with these numbers you get 3.7 as a result. My version of Python yielded 3.666666667, yours might round it up to 3.7. That's fine!)

Requirements

Your program should prompt the user for the information in the same order shown in the example. Failure to follow the same order exactly will prevent your program from being tested correctly.

Your program should output the same information as shown in the example. This will include the number of assignments, the lowest assignment grade (more on this later), the sum and the average of the assignment grades, and the final grade.

Feel free to output the information in as user-friendly a format as you wish it to be!

Finding the smallest element in a sequence

To find the smallest element of a sequence of numbers, you can use the min() function. Run python in interactive mode, and try the following commands to understand how min() works.

>>>  a = [ 3, 10, 23, 1, 39 ]

>>>  min( a )

So, you can use min() to find the smallest of a sequence of grades.

Recommendations

Put all your python statements inside a main() function, and make sure you call main() at the end of your python program. Start small! Just start with a program that gets a fixed number of hw assignments, say 5. Make it compute the average of this series and display it. Then figure out how to find the smallest grade and print it And continue from there, thinking of how you can modify what you have to make it deal with a variable number of grades, depending on how many the users wants to enter.

Testing

Note from DT: I modified the requirements for the testing of the special case when the number of homework assignment is 1. It is too challenging to make sure it works with just the Python we have seen so far, so I will not be testing your programs with fewer than 2 assignments!.

Make sure you test your program with extreme cases. For example, your program should work correctly if the user enters 1 for the number of homework assignments. Making the program work for 0 is not really possible with the amount of Python we know, but if you want to give it a try, you'll get extra credits!

Submission

Submit your program as follows:

      submit hw4  hw4a.py

Problem #2

Write a Python program inspired for the section of the lab dealing with lastlog that will print the last login time for all the professor accounts in the CS Department.

In the CS Department, every course has a professor account created just for the course, for the given semester. For example, this semester, we have a 111b account for Judy Franklin, a 249b, a 250b, etc. The letter b is for courses offered in the Spring semester. We use the letter a for Fall courses.

Your assignment

Write a program that reports the last login time for the professor accounts for the following (not all inclusive) list of classes: 111, 112, 220, 231, 240, 249, 250, 270, 260, 352. We want to know the login for both the Spring and the Fall semesters.

Requirements

Use nested (one inside the other) for-loops.

Typical Output

Username         Port     From             Latest
111a             pts/6    cpe-76-169-53-76 Wed Dec 23 00:01:23 -0500 2009
Username         Port     From             Latest
111b             pts/7    c-24-34-195-85.h Wed Feb 17 10:40:21 -0500 2010
Username         Port     From             Latest
112a             pts/1    131.229.77.229   Tue Dec 15 11:45:16 -0500 2009
Username         Port     From             Latest
112b                                       **Never logged in**
lastlog: Unknown user or range: 220a
Username         Port     From             Latest
220b                                       **Never logged in**
Username         Port     From             Latest
231a             pts/1    c-24-34-195-85.h Wed Jan  6 10:19:31 -0500 2010
lastlog: Unknown user or range: 231b
Username         Port     From             Latest
240a                                       **Never logged in**
lastlog: Unknown user or range: 240b
lastlog: Unknown user or range: 249a
Username         Port     From             Latest
249b             pts/16   131.229.100.253  Wed Feb 17 15:48:09 -0500 2010
lastlog: Unknown user or range: 250a
lastlog: Unknown user or range: 250b
lastlog: Unknown user or range: 270a
lastlog: Unknown user or range: 270b
lastlog: Unknown user or range: 260a
lastlog: Unknown user or range: 260b
lastlog: Unknown user or range: 352a
Username         Port     From             Latest
352b             pts/16   beowulf.csc.smit Wed Feb 17 15:36:07 -0500 2010

Submission

Submit your program as follows:

     submit hw4 hw4b.py