- Creating variable following Python naming convention
- Reading/output data from/to VS Code Terminal
- Converting string data type to integer
- Using the two types of loop: While and For
- Arithmetic operations with BEDMAS Rules
- Using lists (Like Arrays in JavaScript)
- If elif condition with logical operators
Create a new Python and save it as .py file as “py-assignment1.py” like py-assignment1.py
- You will use print() to print the output in the terminal window
- The assignment was designed to be similar like the challenges that you have been using by adding hints and notes about the solution
- This assignment document contains screen shot for the output to give a better understanding and a clear idea about the final result
- Please feel free to use any other ways or logic you prefer or you like since you will get the same results at the end
-
You will ask the user to enter how many courses did he/she finish using the input() built-in function:
- The text to be displayed with the print: “How many courses did you finish?”
- Declare a variable named “num_of_courses” to save the number of courses (which is the value that will be returned from the print function based on the user’s input). The “num_of_course” should be just an int variable (variable with integer value).
- Make sure that the input value (which is string) is converted into number (numeric) using the appropriate Python built-in function that we covered in our lectures
-
Declare an empty list (empty array in JS), this array variable will be used to contain the course marks (later) named “course_marks”. This “course_marks” will be just an empty list exactly as we did in
-
You will use “while loop” loop for a specific number of times based on your variable num_of_courses, for example if num_of _courses value is 5 as shown in the image above, you will make the loop iterate for 5 times. In each iteration of the loop, you will ask the user to enter his/her course mark. This mark will be inserted into the list “course_marks” immediately (instantly), so you will populate this list with the user input through this while loop.
-
After the user finish inserting all their value into our list “course_marks”, use “for loop” to print the items of course_marks list
- You will find the average for all the courses:
- First you need to find the total of all the courses marks inside the list (for sure) using any kind of loop
you want
- The math formula for average ➔ The total of the numeric values / How many numeric values
- Then you can divide the total of the courses by the number of courses and assign the result into a new
variable named “average”
- In our Py assignment ➔ The total of all the marks inside our list / The length of our list
- Print the following sentence: “Your average for your 5 courses is: 88.0”
- First you need to find the total of all the courses marks inside the list (for sure) using any kind of loop
you want
- Output (print) the grade, so you will use “if condition” to check the average value as explained below:
- If average >= 90 and average <=100 ➔ display: “Your grade is A+”
- Else If average >= 80 and average <=89 ➔ display: “Your grade is B”
- Else If average >= 70 and average <=79 ➔ display: “Your grade is C”
- Else If average >= 60 and average <=69 ➔ display: “Your grade is D”
- Else If average <60 [or just use else] ➔ display: “Your grade is F”