Computer Science, asked by akarshshukla496, 5 months ago

राइट ए पाइथन कोड टो स्टोर एंड नंबर ऑफ सब्जेक्ट इन उप्पल​

Answers

Answered by shruti8888
1

Answer:

Write a Python program that accept name of given subject and marks. Input number of subjects in first line and subject name, marks separated by a space in next line. Print subject name and marks in order of its first occurrence.

Sample Solution:

Python Code:

import collections, re

n = int(input("Number of subjects: "))

item_order = collections.OrderedDict()

for i in range(n):

sub_marks_list = re.split(r'(\d+)$',input("Input Subject name and marks: ").strip())

subject_name = sub_marks_list[0]

item_price = int(sub_marks_list[1])

if subject_name not in item_order:

item_order[subject_name]=item_price

else:

item_order[subject_name]=item_order[subject_name]+item_price

for i in item_order:

print(i+str(item_order[i]))

Explanation:

hope hope it helps you.

Similar questions