-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (35 loc) · 1.67 KB
/
main.py
File metadata and controls
40 lines (35 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Welcome message
print("""Welcome to Grades Generator App.
By now you will have received your scores for the subjects that you sat an exam for.
Using this app will help you identify what grade you have achieved.""")
print()
#Assign key variables
subject = input("Please type the subject: ")
maxMarks = int(input("Please type the maximum marks available for your chosen subject: "))
myMarks = int(input("Please type the actual marks you achieved for your chosen subject: "))
#Work out calculation for marks achieved as a %, then round to 2 decimal places
#Also known as variable re-assignment.
percentageMarks = float((myMarks / maxMarks) * 100)
percentageMarks = round(percentageMarks,2)
#Display the marks
print()
print("Your % Marks is: ", percentageMarks,"%")
#code to assign the % marks as a grade
if percentageMarks < 50 :
print("Your grade is", "\033[31m", "U")
elif percentageMarks >= 50 and percentageMarks <= 59:
print("Your grade is", "\033[35m", "D")
elif percentageMarks >= 60 and percentageMarks <= 69:
print ("Your grade is", "\033[33m", "C")
elif percentageMarks >= 70 and percentageMarks <= 79:
print("Your grade is", "\033[32m", "B")
elif percentageMarks >= 80 and percentageMarks <= 89:
print("Your grade is", "\033[36m", "A")
elif percentageMarks >= 90 and percentageMarks <= 100:
print("Your grade is", "\033[34m", "A+")
else:
print("Sorry - the App is unable to work this out!")
#Extra: added colours to the grades, welcome message, ensured float was utilised, clean code.
#Note: Alternatively, rounding can be done in one line
#percentageMarks = round(float((myMarks / maxMarks) * 100), 2)
#I sought feedback and refactoring guidance via the in-built Assistant.