We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defmain(n:int,name_and_marks:str,query_name:str)->float:ifnotisinstance(n,int)orn<=0:raiseValueError("n must be a positive integer")ifnotisinstance(name_and_marks,str):raiseTypeError("name_and_marks must be in str format")ifnotisinstance(query_name,str):raiseValueError("query_name must be a string")lines=name_and_marks.strip().splitlines()name_and_marks_dict={}forlineinlines:parts=line.split()name=parts[0]scores=list(map(float,parts[1:]))name_and_marks_dict[name]=scoresifquery_nameinname_and_marks_dict:scores=name_and_marks_dict[query_name]returnround(sum(scores)/len(scores),2)else:raiseValueError(f"{query_name} not found in the records.")if__name__=='__main__':n=int(input())name_and_marks="\n".join(input()for_inrange(n))query=input()result=main(n,name_and_marks,query)print(f"{result:.2f}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Finding the percentage
You are viewing a single comment's thread. Return to all comments →