            # Functions Lab

Sue Evans & James MacGlashan

# Overview

Objectives for today's lab:
• Understand the grading scheme for CMSC 201
• Be able to break a program down into multiple functions
• Practice writing function definitions and calling them
• This lab is used again for the next lab!!
If you do not complete your lab here in your discussion, you must finish before next week!!

• You will be writing a program that computes the weighted final grade for a 201 student.
• For this task, you'll be provided a file, lisa.txt, containing the student's name followed by each of the assignment weights and corresponding grades, with one piece of information on each line.
• You will use redirection in order to:
• read the data from the file.
• produce the result in the file grade_report.txt
• Your program will produce a grade report for that student which contains the student's name, their course score and their letter grade for the course.
• lisa.txt has the following content:
• lisa.txt
```Lisa					<-- Name
0.03					<-- Homework 1 Weight
0.03					<-- Homework 2 Weight
99					...
0.03					...
89
0.03
90
0.03
100
0.03
100
0.03
98
0.03
95
0.08					<-- Project 1 Weight
0.08					...
100
0.25					<-- Midterm Weight
0.25
92
0.10					<-- Lab/Discussion Weight
34					<-- TOTAL (of best 10) out of 30 pts!! (But Lisa got extra credit!)
```
• To get a copy of this file, use the following command:
• ```
cp /afs/umbc.edu/users/s/l/slupoli/pub/labCode201/lisa.txt .

```

# What is redirection?

• redirection SUBSITUTES a file for the input you normally type on a KEYBOARD
• your code has NO IDEA that the input is coming from the file
• the code is still using input and raw_input respectfully
• THIS IS NOT FILE IO, just a simple substitute
• You need to create the file for redirection NORMALLY, but we already gave you the file named "lisa.txt"
```python lab5.py < lisa.txt
```

# The Functions:

• You should implement the following CONSTANTS for your program named lab5.py:
• FILE_LEN - number of score related entries in the file Lisa.txt
• LAB_POINTS_POSSIBLE - total amount of lab points possible excluding extra credit
• You should implement the following functions for this program:
• findLabScore(rawLabScore) - This function takes the raw lab score as shown in the file in the range of 0 - 30 and calculates a final lab score in the range of 0 - 100. See the more detailed instructions later in the lab.
• findCourseScore(courseDataList) - This function gets passed a list of assignment weights and scores, arranged with the assignment's weight followed by its score in the next position. This function is to calculate and return the course score.
• Requires a properly running "findLabScore" method to calculate the lab score portion
• findLetterGrade(courseScore) - this function takes the numeric course score and returns the letter grade, a string, either 'A', 'B', 'C', 'D', or 'F'
• main()
• The completed main is below. Copy the code into your project
```
def main():
# DO NOT CHANGE MAIN!!
# DO NOT CHANGE MAIN!!

# courseDataList needs to be initialized
courseDataList = []

#gather name, which is the first item on Lisa.txt
name = raw_input()

#create a list from the file Lisa.txt
for i in range(FILE_LEN):

#grab the rest of the values from the file and place into my list
courseDataList.append(input())

courseScore = findCourseScore(courseDataList)

print "%s: %.2f - %c" % (name, courseScore, letterGrade)

main()
```

# Calculating the Lab Score

• To make this lab a little easier, rather than listing all of the 12 lab scores individually, having you find the top 10 scores and returning their total, we've already done that for you. However, the total lab score shown is still a raw score that needs modification.
• Remember that the score for each lab is in the range of 0 - 3. Since the total in the file is for 10 labs, the total is in the range of 0 - 30, without the extra credit. All of the other scores shown in the file are in the range of 0 - 100. So the raw lab score needs to be modified to be in the range of 0 - 100 too.
• Since there is 1/2 pt of extra credit possible for 10 of the labs, even though the range is 0 - 30, a student could have a score of as much as 35. This should not affect your calculation; the calculation should be done as if the highest possible raw score is 30. A raw score above 30 should produce a lab score over 100. After all, that's what extra credit is all about!

Here is what the grade report should look like:

```Lisa:  95.49 - A
```