There are 2 ways you could do this. Which one depends on how exact you have to be with the % values, as none of those numbers are precisely what they account for in the final grade.
Total score: 170
Assignment = 20/170 = 11.7%
Test = 50/170 = 29.4%
Exam = 100/170 = 58.8%
So if getting an 11% with a 20/170 score is okay, then just returning the sum of the scores over the total possible score (170) would work.
HOWEVER, if you have to keep it like your example, then there are 2 parts to getting the final grade. It’s basically the same idea as above, but with an extra step.
So what you want to do is get the relative grade for each section, multiply the associated % value by that number, then add all 3 together.
If you get a 10 in assignments, that’s 10/20, or 50%. 50% of 20% is 10%.
You get a 33 in test, that’s 33/50, or 66%. 66% of 30% is (about) 20% (19.8)%
Finally you get a 78 in exams, that’s 78/100, or 78%. 78% of 60% is (about) 47% (46.8%)
In reality you got a 121/170, or about a 71%, but according to these numbers you got a 77%