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.
Finding the percentage
Finding the percentage
Sort by
recency
|
3881 Discussions
|
Please Login in order to post a comment
I used a dictionary to store each student’s name and their marks. Then I took the query name, calculated the average of their marks, and printed it using f-string formatting. It was easy using Python features like *line unpacking and map() for conversion.
if name == 'main': n = int(input("enter number of students:")) student_marks = {} for _ in range(n): name, *line = input().split() scores = list(map(float, line)) student_marks[name] = scores
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()
#Gest the list of scores from the query using list() --> total the sum --> find #the average --> print using string formatting print(f"{avg:.2f}") 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()
`
if name == 'main': n = int(input()) student_marks = {}