** This assignment was due in Moodle on Monday, January 31 at 12:00AM. To view a sample solution, click on the file name next to each part. **

This assignment has three parts. Create one Python program for each part and store each program in a separate file with the suggested name (instructions on how to do so will follow shortly). All three parts require you to use variables, numbers, strings, mathematical operators, and the print() function demonstrated in the Week 2 lecture and lab. The last of the three parts requires you to define functions and acquire user data via the input() function as demonstrated in the Week 3 lecture and lab.

All three parts require you to use the format(...) method for output demonstrated in the Week 3 lecture and lab, but don't let that prevent you from starting the first two parts beforehand. You can add this feature very easily to your existing code once you have learned it in Week 3.

From within IDLE, select

. You can type your multi-line Python program in this window. Within this window, select to save your program. Make sure you save your file with a .py extension, which denotes a Python program.To run your program, select Python Shell window.

; your program will be interpreted by Python and any output or input will take place within the Consider a triangle with three sides of length **a**, **b** and **c**:

The semiperimeter **s** of this triangle is defined as

Heron's formula states that the area **A** of the triangle can be calculated using

Write a Python program with five variables: one each for the lengths of the sides of the triangle, one for the semiperimeter and one for the triangle's area. Assign the integer values of your choice to the variables representing the lengths of the sides of the triangle; user input is not required. Calculate the semiperimeter and the area using Heron's formula. Your program must display the following output to the user (with possibly different numeric values):

Side a is of length 5 Side b is of length 6 Side c is of length 7 The semiperimeter of the triangle is 9.00 The area of the triangle is 14.70

Note that the area is only displayed with two decimal places. This **must** be guaranteed using the format(...) method.

**Tip:** taking the square root of a number is identical to using an exponent of 0.5.

Examine the marking scheme for CISC 101. Write a Python program with the following variables:

- one for each assignment mark (e.g., 14)
- one for the maximum assignment mark of 15 (assume this is the case for all assignments)
- one for each test mark (e.g., 22)
- one for the maximum test mark of 24 (assume this is the case for all tests)
- one for the final exam mark (e.g., 78)
- one for the maximum final exam mark of 100
- one for the final grade

Assign the integer values of your choice to the assignment, test and final exam mark variables **but not** the maximum mark variables; user input is not required. Calculate the final grade for CISC 101 using the variables given above. Your program must display the following output to the user (with possibly different numeric values):

The mark for assignment 1 is 12/15 The mark for assignment 2 is 14/15 The mark for assignment 3 is 11/15 The mark for test 1 is 18/24 The mark for test 2 is 20/24 The mark for test 3 is 21/24 The mark for the exam was 81/100 The grade for the course is 81.41

Note that the grade is only displayed with two decimal places. This **must** be guaranteed using the format(...) method.

For this part you will be taking your program from Part Two, altering it to use functions and enhancing it with user input. First, transform your program from Part Two into a function calculateFinalGrade(...) with seven parameters to replace the seven variables used to store assignment, test and exam marks. Second, create a main() function which asks the user to enter the marks for each assignment, each test and the exam. This function will then call calculateFinalGrade(...) to determine the final grade and output the results to the screen. Don't forget to call the main() function at the end of your program. Your program must display the following output to the user (with possibly different numeric values):

What was the result for assignment 1? 12 What was the result for assignment 2? 14 What was the result for assignment 3? 11 What was the result for test 1? 18 What was the result for test 2? 20 What was the result for test 3? 21 What was the result for the final exam? 81 The mark for assignment 1 is 12/15 The mark for assignment 2 is 14/15 The mark for assignment 3 is 11/15 The mark for test 1 is 18/24 The mark for test 2 is 20/24 The mark for test 3 is 21/24 The mark for the exam was 81/100 The grade for the course is 81.41

**Tip:** don't forget to convert string input values into integers before doing the calculations.

- You may assume that the user will enter numbers for grades; you do not have to check for non-numeric input
- Efficient but descriptive comments and good variable names are essential

Category | Part | Elements | Marks |
---|---|---|---|

Correctness | Part 1 | Meets the requirements (e.g., variables) Correctly calculates the semiperimeter and the area |
3 |

Part 2 | Meets the requirements (e.g., variables and output) Correctly calculates the final grade |
4 | |

Part 3 | Meets the requirements (e.g., functions and input) Correctly asks for all the necessary input Correctly calculates the final grade from the input |
5 | |

Style | Appropriate comments and variable names "Readable" code |
3 | |

Total | 15 |