top of page
Writer's pictureKrunal Chandan

Python #7 : Finding the Percentage




Welcome all to our new blog of our first series i.e., HackerRank Python Solutions, where we provide solutions to the problems given on HackerRank Website of Python. We are today going to discuss about one of the tough problems given in the EASY section, well to be honest it should be given in the MEDIUM section, but as whose thinking, what should we do.



Today's topic is Finding the percentage, well first of all if you didn't know anything about the Sets, Lists, Tuples, and Dictionaries in Python, I must say, you have to either read about it, or else you have to watch tutorials, or courses about what that is, else you cannot understand what is going on here.


So go and watch what are those and the come back, here. So today we will find percentage of students, given in a Dictionary format, or as I can say, given by user. So we just have to input the values, i.e., their marks and then give choice from which user will choose and we will print its percentage.

As we can see in this image, the user will input all the values i.e., the names and the marks and we then have to calculate and output the marks, percentage. Hence for this below code is just not the only option but is one them, so you can copy this code and paste it in the compiler there and you can have the problem solved.


// Code


def average_marks(students, name): marks = students[name] avg = sum(marks) / len(marks) avg2 = "{:.2f}".format(avg) return avg2 if __name__ == '__main__': n = int(input()) student_marks = {} for _ in range(n): name, *line = input().split() scores = list(map(float, line)) student_marks[name] = scores query_name = input() print(average_marks(student_marks, query_name))


Explanation :

Here, we are just making a function that will calculate the percentage and will store in a variable that we later will just return to the main function, and will print to show our result. Well at first we will call all the values from the dictionary created for storing all the values. Then we will just, add all the values, and then divide it by number of values, in this case it is 3, but if we make it more user friendly, it will depend on all number of terms stored in it.



Hence now that we have covered our topic, you can comment down topics, you want us to make blog on, we will appriciate it and will try to make blog as soon as possible. Just make sure to subscribe to it, we will be sending post updates, as soon as it is Published.


Till Then, #Coders 😎....

5 views0 comments

Recent Posts

See All

Last Blogg For KNBLOGGS

My last blogg about gaming from your android, or my other blogs, that I published earlier were not a big hit, not like this website or...

Комментарии


About Us

LOGO_MAIN.jpg

Welcome to KN Blogg, the place where we're serious about tech, finance, movies, and games. Or at least, we try to be. We're a team of self-proclaimed experts, enthusiasts, and sometimes just plain clueless individuals, who love to share our thoughts, opinions, and occasional witty remarks with the world.

Posts Archive

Tags

bottom of page