Goals Practice using Booleans and conditional structures Practice writing functions Practice calling functions from anot
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Goals Practice using Booleans and conditional structures Practice writing functions Practice calling functions from anot
The following steps summarize the project tasks: 1. Task 0: program set up and add short description comments in the header area. 2. Task 1: implement the following functions that calculate points for each factor. 0 calcAttendanceScore calcHomeworkScore calcMidtermScore calcFinal Score calcLateSubmissionScore 3. Task 2: implement the make Decision function that does the following: • Calculates the point for each factor by calling the corresponding functions. • Uses the factor points and the weights to calculate the final grade and returns whether the student can PASS or FAIL this course (criteria: students who pass the course have a final grade of 60 or above) ■ The weights of each factor are listed as follows: 5% Attendance: Homework: Midterm: 20% Final: Late Submission: 30% 40% 5% 4. Task 3 implement the main function that does the following: • Reads from the user the number of students n to process. • Loops for n times, in each iteration, it calls make Decision, and prints the decision returned by the function. Task 0: Open a new, blank Python program window. Save the files as project02.py At the top of the file, enter the following: # CS 177 project02.py # (insert your name here} # summarize the project in a few sentences Task 1: Use the following table to implement calcAttendanceScore, calcHomeworkScore, calcMidtermScore, calcFinalScore, calcLate SubmissionScore
1 2 3 4 5 Factor Attendance Score Homework Score Midterm Score Final Score Late Submission Score Value Ranges yes no 0 1-60 61-100 101-200 201 - 400 0-20 21 - 60 61-80 0-20 21-40 41-60 61-80 81-90 91-100 0-10 11-20 21 or more Factor Points 100 0 0 25 50 75 100 0 50 100 0 20 40 60 80 100 100 50 0 Details: def calcAttendanceScore (attendance Factor): The function returns 100 when the attendance Factor value is yes, otherwise 0 def calcHomeworkScore (hwFactor): Depending on the the value of hwFactor, the function returns 0, 25, 50, 75 or 100 def calcMidtermScore (midtermFactor): Depending on the value of midtermFactor, the function returns 0, 50 or 100 def calcFinalScore (finalFactor): Depending on the value of finalFactor, the function returns 0, 20, 40, 60, 80 or 100. def calcLate SubmissionScore (lateFactor): Depending on the late Factor, the function returns 0, 50, or 100
Task 2: implement the make Decision function def makeDecision (attendance, homework, midterm, final, latesub) : You may think about the make Decision function as the grade calculator of this course. Given the five factors (attendance, homework, midterm, final and late submission), it computes the final grade and returns two values: 1. the calculated final grade 2. the final decision as a string type PASS or FAIL. Useful Tip: when returning multiple values from a function, separate the values by a comma, return vall, val2, val3, A common mistake is returning a list: return [vall, val2, val3, .] which in turn is a single returned value of a list type The weights of each factor is listed as follows: Attendance: 5%, Homework: 20%, Midterm: 30%, Final: 40%, Late Submission: 5%. Moreover, the students with a score of 60 or more can PASS this course Here is a suggested outline to implement make Decision # use the make Decision parameters to call calculate the points # of each factor attendanceScore = calcAttendanceScore (attendance) homeworkScore = # Use the calculated points to compute the final grade # Use decision structure to determine the final decision Task 3 implementing the main function The main function serves as an entry to the program. The user input is typically read inside the main and the related functions are called to carry out the intended operation. Here is a suggested outline to implement main: # Read the number of students (n) from the user #Loop n times # For each iteration -------
# For each iteration # print the student number header # Read the factors from the user # Call makeDecision to get the course final grade and #final decision # print the decision Comments: your program should have a header for each function and comments that explain the solution steps. Calling the main function updated on 6/25/2022 5:08 pm Please use the following syntax to call the main function # the main function def main (): #main implementation # # calling the main function == "1 _main___": if name main () The reason, this syntax allows treating your submitted python file as a library that can be easily imported from Python's command line. We will go over the syntax in the recitation. For now, here's how to import your code as a library and test individual functions: >>> project 02 import * >>> print (calcAttendance Score ("yes")) 100 Sample Output Enter the number of students: 2 Student #1 Enter attendance score: yes Enter homework score: 350 Enter midterm score: 80 Enter final score: 90 Enter late submission score: 1 Decision: (92.0, 'PASS') Student #2 Enter attendance score: no Enter homework score: 100 Enter midterm score: 40 Enter final score: 30 Enter late submission score: 25 Decision: (33.0, 'FAIL')