# Grading Students

# Grading Students

cakerusk + 39 comments Java one-liner code :

System.out.println(grade < 38 || grade % 5 < 3 ? grade : grade + (5 - (grade % 5)));

eavestn + 0 comments [deleted]eavestn + 0 comments [deleted]eavestn + 5 comments Nice solution. I am writing in C#, myself. I def. had to start with a more fleshed-out solution and work my way down to this. I wonder if a lengthier solution would be more communicative of the imposed requirements. I pushed mine up as a one-liner, though.

cakerusk + 7 comments Thanks. A lengthier solution might improve readability but compromise on lines of code (maintainability). Either way it doesn't affect runtime, so it comes down to a matter of personal preference I guess. :)

sungmkim80 + 1 comment I don't agree that a lengthier answer would compromise maintainability. If you deal with a smaller chunk of code, it's easier to maintain as you can focus on a narrow logic.

cakerusk + 1 comment Probably not in this question but I pointed that out in general from an interview/development perspective. For this particular qs, it's only a matter of preference.

JavaANDHannah + 1 comment It's a terrible solution. Hello? Have you ever heard of the words, "RE-READ YOUR WORK?" Oh, and plus, it doesn't work. :)

cakerusk + 2 comments It works perfectly fine.

https://www.hackerrank.com/challenges/grading/submissions/code/39368045

In case of issues, let me know.

uniyal_guru + 6 comments I have another solution for the same.

static int[] solve(int[] grades){ // Complete this function for(int i=0;i<grades.length;i++) { if(grades[i]>=38) { if(grades[i]+(5-grades[i]%5)-grades[i]<3) grades[i]=(grades[i]+(5-grades[i]%5)); } } return grades; }

doctorj0023 + 2 comments I did this with backward iteration and without your most inner If:

for(int i = grades.Length-1; i >=0; i--) { if(grades[i] >= 38 && grades[i] % 5 >2) { grades[i] = grades[i] + (5 - (grades[i] % 5)); } }

alexb760 + 3 comments in your solution what happen if grade[i] = 67 them grades[i] % 5 = 7 and them 5-7 = -2 so 67 -2 = 65

keickhoff1 + 1 comment No, it will not pass the second condition of the if statement. Because 67 % 5 = 2 not 7.

navinchainani74 + 0 comments same douth i dont understand how we will multiple by 5

harshrajan00 + 1 comment [deleted]harshrajan00 + 0 comments As @keickhoff1 pointed out 67 remains 67.

anshulbadyal11 + 0 comments please correct yourself and please do learn how to use modulus operator

PareshSalunke + 0 comments Your solution is perfectly fine but as a first draft. Whenever possible take out common operations and put it in a variable so next time what if the moderator said that multiple of 6 instead of 5 . you'll have to change at 2 places in your case but it may be a become bigger issue in complex chunk. Just saying. :)

hard_system + 0 comments very good, by the way it has to be grades.Length

avi_ganguly94 + 1 comment in the inner if() , why did you do a grades[i] + blahBlahPivot - grades[i]? i mean, grades[i]-grades[i] is zero anyway so why bother?

ssaulakh2 + 0 comments [deleted]

krishna_kumar_b1 + 0 comments this program have some error check your program

tazpandey + 1 comment Your answer is nice.But why you put -grades[i]<3 in if condition can you explain it.

harshrajan00 + 0 comments (5 - grades[i] % 5) < 3 if this is the condition you are talking about then the question says that If the difference between the grade and the next multiple of 5 is less than 2.

devin99 + 0 comments Your link doesn't work, like the code provided above

rabbyalone + 2 comments my solution

static int[] solve(int[] grades) { int[] res = new int[grades.Length]; for (int i = 0; i < grades.Length; i++) { if (grades[i] % 5 > 2 && !(grades[i] < 38)) res[i] = grades[i] + (5-grades[i]%5); else res[i] = grades[i]; } return res; }

aliriomambo + 0 comments [deleted]van07 + 3 comments Would this be better? For reability only. Im not sure. It's really the same solution.

int[] res = new int[grades.Length];

`for (int i = 0; i < grades.Length; i++) { int current = grade[i]; if (grades[i] % 5 > 2 && !(grades[i] < 38)) current = grades[i] + (5-grades[i]%5); res[i] = current; } return res;`

skoffice47 + 1 comment Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks voyance gratuite immediate par telephone

karishmasingh401 + 0 comments I was searching for this for a long time and I like the way you have written this wonderful post.

**Delhi Escorts Service**

karishmasingh401 + 0 comments Usually, it is good to know about this wonderful article and I wish you have many different ideas to share with all of us.

**Escorts in Delhi**karishmasingh401 + 0 comments This is an epic chance for me to write my own reviews and I was hoping for this for a long time.

**Delhi Escorts**

aaronederby + 0 comments You are right. There is a pretty big epedimic of poor readability in coding these days. Some of these projects are pretty good proof of that.

munna1991vikram + 0 comments Get the complete information of windows 10 operating system by visiting here on this website. windows 10 free download Because this website provides us complete information of windows 10 operating system in your personal computer.

skoffice47 + 0 comments In the world of www, there are countless blogs. But believe me, this blog has all the perfection that makes it unique in all. I will be back again and again. Fortnite V bucks generator

skoffice47 + 0 comments Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? Iâ€™ve a undertaking that I am simply now operating on, and I have been at the look out for such info. viking appliance repair near me

skoffice47 + 0 comments Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? Iâ€™ve a undertaking that I am simply now operating on, and I have been at the look out for such info. Demir Leather

piyushhajare + 6 comments A simple and perhaps readable solution.. You can use n instead of temp as its just a dummy..

int main() { int n,temp; cin>>temp; while(cin>>n) { if(n<38) cout<<n<<endl; else if(n%5 >= 3) cout<<n+ (5-n%5)<<endl; else cout<<n<<endl; } return 0; }

owenized + 1 comment Why use EOF?

deepesh463 + 0 comments it stands for end of file

agnivabasak1 + 1 comment according to me it shouldn't work but if it passed test cases ,then i dont know how .the reason is that consider a number like 73 ,then n%5 should give 3 ,and hence it would redirect to the else statement and print n, whereas it should have printed 75 as we need to consider the next multiple of 5 ,75-73 =2 (<3) .Correct me ,if i am wrong ,anyone. (might be i am wrong too :P ,i developed my solution in my way ,though!)

steven_tang + 1 comment 73 % 5 = 3 and 3 <= 3, so it'll satisfy the else if condition. Then we have cout << 73 + (5- 73%5) << endl; which simplifies to cout << 73 + 2 << endl;

zeashaikh3306 + 0 comments Why are we checking <=3 and not some other number?

vijayashreeshet1 + 0 comments wow ..thank u

samarthdatir11 + 1 comment cant understand use of temp here

nick_mehta2k19 + 0 comments

JavaANDHannah + 0 comments [deleted]borb_ + 1 comment You can do the same thing in C# ->

return grades.Select(grade => grade < 38 || (grade % 5 < 3) ? grade : grade + (5 - grade % 5 )).ToArray();

return grades.Select(grade => grade < 38 || (grade % 5 < 3) ? grade : grade + (5 - grade % 5 )).ToArray();

sidra_mbn + 1 comment Excellent

sidra_mbn + 1 comment Can you please also tell me that ToArray is to be used only when we are returning an array?

moh_so2001 + 0 comments `foreach(`$grades as $`grade){`

grade < 38 || grade : grade % 5))); } return $g;

php code

eavestn + 1 comment Don't know why I got downvoted for a simple comment?

mehreensiddique1 + 1 comment Thank you for taking the time to publish this information very useful! idrqq

mehreensiddique1 + 0 comments Thank you for taking the time to publish this information very useful! laser headlights price

rajatdhoot + 0 comments Great Solution.........

alexandre_ragal1 + 4 comments Got some fun with Java 8:

Arrays.stream(new int[n]).map(i-> in.nextInt()).map(g -> (g >= 38 && g % 5 >=3) ? g+5-g%5 : g).forEach(System.out::println);

jude_niroshan11 + 0 comments nice shortcut for nearest 5th divisible value.

g+5 - g%5

ashishsinghchau1 + 1 comment Does not working out.It did some basics mistakes on the Editor.

alexandre_ragal1 + 0 comments It is working since I passed all tests.

public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); Arrays.stream(new int[n]).map(i-> in.nextInt()).map(g -> g >= 38 && g % 5 >=3 ? g+5-g%5 : g).forEach(System.out::println); }

a_gutsal + 0 comments Arrays.stream(grades).map(grade -> (grade < 38) || (grade % 5 < 3)?grade:((int)(grade / 5) + 1) * 5).toArray()

ismailkuet + 1 comment Get some fun with Python 3::

return [n if n < 38 or n % 5 < 3 else (n + 5 - (n % 5)) for n in grades]

nvinson234 + 2 comments A lot of modulo use when it's not really needed. An alternate version:

return [max(n, (n + 2) // 5 * 5) if n >= 38 else n for n in grades]

auratice + 0 comments it would be really helpful if you could explain this. thank you!

j0096 + 0 comments Nice. I think it is little bit more readaable if you use the same approach but use a single modulus:

return [max(n, 5 - (n % 5) + n) if n > 37 else n for n in grades]

(Sorry format as code button is missing from editor)

Cuteboy06 + 1 comment Can anyone explain me how it is printing grade for the values like 67.

cakerusk + 3 comments The rules for rounding off is stated as follows :

If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5. If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.

Since the value 67 is greater than 38 and the difference between value and next multiple of 5 (i.e. 70) is 3 (70 - 67) which is not less than 3, it will not be rounded. Hence, 67 i.e. 'grade' value is printed.

However, for the value 68, the difference is 2 (70 - 68) < 3, so the grade will be rounded to the next multiple by the calculation :

*grade + (5 - (grade % 5)) = 68 + (5 - (68 % 5))**= 68 + (5 - 3)**= 68 + 2**= 70 (next multiple of 5)*Hope this helps! :)

Cuteboy06 + 0 comments Thanks for your time :)

TejanSD17 + 0 comments Thank you.

alternativo_vini + 0 comments thanks

piyushhajare + 1 comment A simple and perhaps readable solution.. You can use n instead of temp as it's dummy..

int main() { int n,temp; cin>>temp; while(cin>>n) { if(n<38) cout<<n<<endl; else if(n%5 >= 3) cout<<n+ (5-n%5)<<endl; else cout<<n<<endl; } return 0; }

bg2407111 + 1 comment Just a tip I've learned from my professors, you should rarely ever have to rewrite the same lines of code, see how your initial if and your default else are doing the same thing? You could condense this by doing this:

`if(n>38 && n%5 > 3) { cout << n+(5-n%5) << endl; } else { cout << n << endl; }`

Makes it still readable, but in less lines of code. Also, in Industry code it's generally good practice to use curly braces on the body of if statements to prevent any confusion.

ssaulakh2 + 0 comments Will I get kicked out if I do this from nothing.

Ardillo + 5 comments Python3 one-liner:

grades = [int(input()) for __ in range(int(input()))]

[print(g+5 - g%5 if g%5 > 2 and g>37 else g) for g in grades]

h201551072 + 3 comments i am new in pyhton can u help me with the mistake?

#!/bin/python import sys def solve(grades): r=[] y=0 d=0 # Complete this function for i in range(0,len(grades)-1): if(grades[i]>=38): y=grades[i]/5 d=5*(y+1)-grades[i] if(d<3): r[i]=5*(y+1) else: r[i]=grades[i] else: r[i]=grades[i] return r n = int(raw_input().strip()) grades = [] grades_i = 0 for grades_i in xrange(n): grades_t = int(raw_input().strip()) grades.append(grades_t) result = solve(grades) print "\n".join(map(str, result))

immanoj16 + 3 comments def solve(grades): result = [] for i in grades: if i >= 38: if i % 5 >= 3: i += (5 - i % 5) result.append(i) return result

JehanJoshi + 0 comments You can club both the if conditions using an and here and neatly get it in one line :)

vishalnirne98 + 1 comment how doesthe second if statement work

utkarshGG + 0 comments oh, that is an equivalent of Ternery Operator ?: in other languages. Do_this

*if*this_is_true*else*do_thissay for example,

>>> x = 10 >>> y = 21 if x > 12 else 5

y will be equal to 21 if x is greater than 12 else y will be 5.

mahmut_bilgen + 0 comments Good solution! Congratulation !

def gradingStudents(grades): # Write your code here result = [] for grade in grades: rounding_num= ((grade // 5)+1)*5 if grade<38 : result.append(grade) elif rounding_num-grade<3: result.append(rounding_num) else: result.append(grade) return result

Mandar_Inamdar + 1 comment you are doing y=grades[i]/5 which will give you decimal numbers. round division using math functions or simply like: y=int(grades[i]/5)

ditonikola + 3 comments #!/bin/python3 import sys def solve(grades): for k in range(0,n): if grades[k]<38: print(grades[k]) else: l=grades[k]/10 m=round(l) if 0.25<abs(l-m)<0.5 or 0.5<abs(l-m)<0.75: a=round(grades[k]/5) b=a*5 c=b-grades[k] if c<0: if c<-3: print(b) else: print(grades[k]) else: if c<3: print(b) else: print(grades[k]) else: f=m*10 d=f-grades[k] if d<0: if d<-3: print(f) else: print(grades[k]) else: if d<3: print(f) else: print(grades[k]) n = int(input().strip()) grades = [] grades_i = 0 for grades_i in range(n): grades_t = int(input().strip()) grades.append(grades_t) result = solve(grades) print ("\n".join(map(str, result)))

whats wrong with this pls tell me, it gives me runtime error, but passes 5 times

_dugy + 0 comments You have to return array of ints from "solve" function.

mtausif_0003 + 0 comments its so complicated logic

ismailkuet + 0 comments One line solution::

return [n if n < 38 or n % 5 < 3 else (n + 5 - (n % 5)) for n in grades]

ismailkuet + 0 comments @h201551072 You can do it in one line with list comprehensions

return [n if n < 38 or n % 5 < 3 else (n + 5 - (n % 5)) for n in grades]

archit_imsec10 + 2 comments And how about this?

map(lambda x: 5*(1 + x//5) if (x > 37 and ((x%5) > 2)) else x, grades)

ahmettortumlu25 + 1 comment so good.

sidra_mbn + 0 comments Thank you

massimiliano_de1 + 0 comments nice one liner, but write something like that in my project and I'll fire you.

you must spare maintainer/programmer time, not whitespaces in the file.

Spiznak + 0 comments 1 iteration, almost 1-liner. O(n) is slightly better than O(2n):

for _ in range(int(input())): x = int(input()) print(x + (5 - x % 5)) if x >= 38 and 5 - x % 5 < 3 else print(x)

I wouldn't be surprised to learn that there is a better way to do it, though...

Dimple151997 + 1 comment Can you explain the code.. why do we write __ in for loop and 2nd line in [] brackets

MilosMM + 0 comments Hi, because we don't care about the value of the iterator.

rudralittle + 0 comments i ran it on my jupyer notebook. i cant understand the output. input>>>>>>>>>>>>> grades = [int(input()) for __ in range(int(input()))]

[print(g+5 - g%5 if g%5 > 2 and g>37 else g) for g in grades]

output>>>>>> 5 45 66 23 56 98 45 66 23 56 100 [None, None, None, None, None]

chris_dziewa + 0 comments I knew I would find something much shorter than my code here but wow! Nice work!

ashishsinghchau1 + 0 comments Your code does not working out in the editor.

arunesh_sarin + 0 comments [deleted]arunesh_sarin + 1 comment but this code should round off 67 as 67%5 is 2 which is less 3 . Help me undertand this please.

borb_ + 0 comments The problem states that the rounding should occur if the DIFFERENCE is LESS than 3. The difference here is 3 so it is not rounded.

ummahusla + 0 comments Wow! Clearly beatiful and cleanest way I've seen so far

SupreethMC + 0 comments Neat !

vijayashreeshet1 + 0 comments i dont understan java .. bt i understood the logic .. thank you:)

UWUTM8 + 1 comment I've got a pretty sick one-liner too for C++ can your boy get some upvotes =D

for (int i = 0; i < grades.size(); i++){int nearest5Multiple = 5*((grades[i]/5)+1);if (grades[i] >= 38 &&(nearest5Multiple-grades[i]) < 3 ){grades[i] = nearest5Multiple;}}return grades;

sfelde21 + 1 comment haha I hope you're joking

ditonikola + 0 comments No im not joking

WatchandLearn + 0 comments it looks good,but keeping result of (grade%5) in a variable could save you from calculating it two times :)

dipznjoy + 0 comments actually not , as it will work for 41,42 . as 41 % 5 =1 , but we want to have the for 43,44. that goes for all the cases.

Tunvir07 + 0 comments Great.

santhoshkumar_n + 0 comments It works

rishabh0_9 + 0 comments This is my solution

static int[] solve(int[] grades){ // Complete this function for(int i=0; i<grades.length; i++){ if(grades[i]>=38 && grades[i]%5>2) grades[i] = grades[i] + (5 - (grades[i]%5)); } return grades;

ramamoorthypand1 + 0 comments [deleted]saiful007 + 0 comments if (grade > 37){ int newGrade = grade; for (int i=1; i<=2; i++){ newGrade++; if(newGrade%10 == 5 || newGrade%10 == 0){ grade = newGrade; return grade; } } } return grade;

vikramhpatel12 + 1 comment won't work for grade =73 since 73%5 is 3

saiful007 + 0 comments i dont think so it pass all the test cases ...but thanks for your kindness

tejasree438 + 0 comments I achived useing my own implementaion upto 20 lines to achieve this code.But your solution is just awe.I will adopt for this technique.Thank you.

rajkumarkanjo + 0 comments nice logic ..

m_eli10 + 0 comments [deleted]harshrajan00 + 0 comments Even my mobile has 4GB ram.

coder_aky + 1 comment # Python 3 , 3-liner

for _ in range(int(input())): g=int(input()) print(g if g < 38 or g % 5 < 3 else g+(5-(g % 5)))

meghrajpardesi + 0 comments # One liner for abouve code

def gradingStudents(grades): return [g if g < 38 or g % 5 < 3 else g + (5 -(g % 5)) for g in grades]

soheil_jahangir1 + 0 comments awesome.

CyberZii + 0 comments Amazing. Bravo!

gabrielbb0306 + 0 comments Your solution is bad for the problem as it is today. You are printing the elements, but the problem, at least today, says you should return the array. If you do the assigning to the array in one line then it is not possible to check when to assign, so you will always assign, which will be much slower. For this reason i will have to give a downvote to your answer. Still pretty cool for a problem that ask to print them instead of returning, tho

vangalasuneel + 0 comments this soluation will not pass all test cases

ismailkuet + 0 comments Get some fun with Python 3::

return [n if n < 38 or n % 5 < 3 else (n + 5 - (n % 5)) for n in grades]

vinayak_prabhut1 + 0 comments This will not work for inputs like 70, 80...

abhishekgowdakm2 + 0 comments int s=grades.size(); List list = new ArrayList();

`for(int i=0;i<s;i++){ int N=grades.get(i); if(N>=38){ int number =N%5; int l = 5-number; if(l<3){ N=N+l; list.add(N); }else{ list.add(N); } }else{ list.add(N); } } return list; }`

nesimi_nezir + 0 comments What is input here? Array or ?

jasonganub + 11 comments A simple and clean solution with only one print statement and minimal conditionals.

if grade >= 38: if grade % 5 == 3: grade += 2 elif grade % 5 == 4: grade += 1 print(grade)

jakemager + 1 comment awesome use of the modulo operation

trungskigoldberg + 1 comment this solution is mathematically cool man

franchetti + 2 comments Could be condensed to a single condition if you wanted.

if grade >= 38: if grade % 5 > 2: grade += 5 - (grade % 5) print(grade)

cuteprince1989 + 0 comments this is such a clever solution great mind...

cuteprince1989 + 1 comment it is not working it is giving me error unsupported operand type for %: list and int. can any help me? there compiler is not working correctly, i have run this code in python 2 in my system it is working fine but not in here

ThaiNguyen + 0 comments You are using grade, which is a list. You have to access the indices in the list using loop like this

for i in grade: if i >= 38: if i % 5 == 3: i += 2 elif i % 5 == 4: i += 1 print (i)

h201551072 + 2 comments new in python can u help me with this code

#!/bin/python import sys def solve(grades): r=[] y=0 d=0 # Complete this function for i in range(0,len(grades)-1): if(grades[i]>=38): y=grades[i]/5 d=5*(y+1)-grades[i] if(d<3): r[i]=5*(y+1) else: r[i]=grades[i] else: r[i]=grades[i] return r n = int(raw_input().strip()) grades = [] grades_i = 0 for grades_i in xrange(n): grades_t = int(raw_input().strip()) grades.append(grades_t) result = solve(grades) print "\n".join(map(str, result))

immanoj16 + 2 comments def solve(grades): result = [] for i in grades: if i >= 38: if i % 5 >= 3: i += (5 - i % 5) result.append(i) return result

debabrata_tah98 + 0 comments [deleted]debabrata_tah98 + 1 comment def gradingStudents(grades):

`result = [] for i in range(0, len(grades)): grades[i] = int(grades[i]) for i in grades: for j in range(1,101): if(j%5 == 0 and j>i): if(i<38): result.append(str(i)) break elif(j-i<3): result.append(str(j)) break else: result.append(str(i)) break return result`

debabrata_tah98 + 0 comments test case 3 and 10 are not passing. can u tell me what is the error?

tomarshubham49 + 0 comments fgfhyhyrihowhhflhiihiw{} bhai yeah galti hai teri program mmm

dylanjcastillo + 0 comments Great solution!

lukus_2222 + 0 comments neat

heres the same solution in PHP

function solve($grades){ for ($i=0;$i <= sizeof($grades); $i++){ if ($grades[$i] >= 38){ if ($grades[$i] % 5 == 3){ $grades[$i] += 2; } else if ($grades[$i] % 5 == 4){ $grades[$i] += 1; } } } return $grades; }

16wh1a05b7 + 0 comments [deleted]lvsz_ + 0 comments A difficult and intricate solution with only one line and

*no*conditionals (nor variables).print . ((uncurry (+) .) . ((. ((*) . fromEnum)) . flip second) <*> (uncurry ((. (>) 3) . (&&) . (<) 37))) . ((,) <*> (flip mod 5 . negate))

sammy9292 + 0 comments fantastic. Such simple logic!!!

max_aka21 + 0 comments You can just group 1st and 2nd if condition into single if condition

the_happy_hacker + 0 comments def gradingStudents(grades): return [g if g < 38 or g%5 < 3 else (g//5+1)*5 for g in grades]

imerljak + 4 comments Javascript with ES6 :)

function solve(grades){ return grades.map((n) => { let diff = 5 - (n % 5); if(diff < 3 && n >= 38) { n += diff; } return n; }) }

hroger19 + 1 comment Wow that's short!

jeremymgould + 1 comment I think you can make it even shorter without hurting readability too badly.

return grades.map(g => (g < 38 || g%5 < 3) ? g : Math.ceil(g/5)*5)

This would work too and is probably a little clearer.

return grades.map(g => (g < 38 || g%5 < 3) ? g : g+(5-(g%5)))

sethkal7 + 0 comments I did the same, and was making the same decision between Math.ceil(g/5)5 and g+(5-(g%5)) I ended up with the following:

`const gradingStudents = grades => grades.map(grade=> grade <= 37 || grade % 5 < 3 ? grade : grade + (5 - grade % 5));`

svl_taylaran + 0 comments Short and sweet unlike mine lol

function gradingStudents(grades) { // Write your code here let finalGrades = new Array(grades.length); for (let x = 0; x <= grades.length - 1; x++) { if (grades[x] >= 38 && (grades[x] + 2) % 5 === 0) { finalGrades[x] = grades[x] + 2; } else if (grades[x] === 99 || (grades[x] >= 38 && (grades[x] + 1) % 5 === 0)) { finalGrades[x] = grades[x] + 1; } else { finalGrades[x] = grades[x]; } } return finalGrades; }

Totally forgot about the map method too.

sidinsomniac + 0 comments My JS solution:

function gradingStudents(grades) { let finalMarks = []; grades.forEach(grade => { grade < 38 || grade % 5 < 3 ? finalMarks.push(grade) : finalMarks.push(Math.ceil(grade/5)*5) }) return finalMarks; }

drpika1134 + 1 comment Can someone explain why he substracts the

`(n % 5)`

from`5`

in line 3?waweruhmwaurah + 1 comment n%5 will give you the remainder of the numbers to make n divisible by 5..

say n = 78

78%5 = 3 // so we have a remainder of 3 if we divide 78/5..

We however do not need the remainder to convert to a number divisible by 5 say we add 3 to 78 we will end up with 81, which is not divisible by 5.

We want to know how far we are from achieving a 5 from the modulus of 78 which is why we then subtract the modulus from 5..

In our case it would be we have a remainder of 3 and from 78 we require 2 (i.e 5-3(remainder) ) to be able to make our number divisible by 5..

sense?

maggiew61 + 0 comments thanks

ikhan77727 + 0 comments python solution

def gradingStudents(grades): return [ i if (i < 38 or i % 5 < 3) else (i + (5 - i%5)) for i in grades]

kevinlai31 + 0 comments C version is broken btw. main function calls "gradingStudents" with undeclared first argument. change the first argument to "n"

Sort 1495 Discussions, By:

Please Login in order to post a comment