Difference between revisions of "CSC111 Homework 4"

From dftwiki3
Jump to: navigation, search
(Problem #2)
(Requirements)
Line 98: Line 98:
 
===Requirements===
 
===Requirements===
  
Use one (or more) for-loops.   Extra credits if you use nested for-loops!
+
Use nested (one inside the other) for-loops.
  
 
===Submission===
 
===Submission===

Revision as of 15:51, 17 February 2010

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


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

Make sure you test your program with extreme cases. For example, your program should work correctly if the user enters 0 for the number of homework assignments, in which case it will not ask for homework grades and will skip directly to the exam grades.

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.

Submission

Submit your program as follows:

     submit hw4 hw4b.py