-1
def mymarks(dict, keys):
    for key in dict:
        print(dict[keys])

marks = {"maths": "85", "chemistry": "70", "english": "76", "biology": '83', "physics": "71"}

mymarks(marks, "chemistry", "biology", "physics")

How can I pass multiple arguments to mymarks() function? I do not want to print all values of the keys of the marks dictionary. I only want to print the values of sciences subjects keys which are chemistry, biology and physics, so the output would be like:

70
83
71

I tried to solve it as following, but this resulted in error.

def mymarks(dict, keys, keys, keys):
    for key in dict:
        print(dict[keys])

mymarks(marks, keys = "chemistry", keys = "biology", keys = "physics")
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

1 Answers1

0
def mymarks(dict, *keys):
    for key in keys:
        print(dict[key])

marks = {"maths": "85", "chemistry": "70", "english": "76", "biology": '83', "physics": "71"}

mymarks(marks, "chemistry", "biology", "physics")

Output :-

70
83
71
Nehal Birla
  • 142
  • 1
  • 14