Computer Science
Can you store the details of 10 students in a dictionary at the same time ? Details include - rollno, name, marks, grade etc. Give example to support your answer.
Python
Python Dictionaries
11 Likes
Answer
n = 10
details = {}
for i in range(n):
name = input("Enter the name of student: ")
roll_num = int(input("Enter the roll number of student: "))
marks = int(input("Enter the marks of student: "))
grade = input("Enter the grade of student: ")
details[roll_num] = [name, marks, grade]
print()
print(details)Output
Enter the name of student: Sushma
Enter the roll number of student: 4
Enter the marks of student: 56
Enter the grade of student: C
Enter the name of student: Radhika
Enter the roll number of student: 3
Enter the marks of student: 90
Enter the grade of student: A+
Enter the name of student: Manika
Enter the roll number of student: 45
Enter the marks of student: 45
Enter the grade of student: D
Enter the name of student: Mitanshu
Enter the roll number of student: 1
Enter the marks of student: 23
Enter the grade of student: F
Enter the name of student: Anshika
Enter the roll number of student: 7
Enter the marks of student: 77
Enter the grade of student: B
Enter the name of student: Purva
Enter the roll number of student: 9
Enter the marks of student: 99
Enter the grade of student: A+
Enter the name of student: Sanjana
Enter the roll number of student: 3
Enter the marks of student: 76
Enter the grade of student: B+
Enter the name of student: Priyanka
Enter the roll number of student: 2
Enter the marks of student: 89
Enter the grade of student: A
Enter the name of student: Anand
Enter the roll number of student: 6
Enter the marks of student: 100
Enter the grade of student: A+
Enter the name of student: Sarika
Enter the roll number of student: 10
Enter the marks of student: 55
Enter the grade of student: B+
{4: ['Sushma', 56, 'C'], 3: ['Sanjana', 76, 'B+'], 45: ['Manika', 45, 'D'], 1: ['Mitanshu', 23, 'F'], 7: ['Anshika', 77, 'B'], 9: ['Purva', 99, 'A+'], 2: ['Priyanka', 89, 'A'], 6: ['Anand', 100, 'A+'], 10: ['Sarika', 55, 'B+']}
Answered By
3 Likes
Related Questions
Write a program that repeatedly asks the user to enter product names and prices. Store all of these in a dictionary whose keys are the product names and whose values are the prices.
When the user is done entering products and prices, allow them to repeatedly enter a product name and print the corresponding price or a message if the product is not in the dictionary.
Create a dictionary whose keys are month names and whose values are the number of days in the corresponding months.
(a) Ask the user to enter a month name and use the dictionary to tell how many days are in the month.
(b) Print out all of the keys in alphabetical order.
(c) Print out all of the months with 31 days.
(d) Print out the (key-value) pairs sorted by the number of days in each month.
Given the dictionary x = {'k1':'v1', 'k2':'v2', 'k3':'v3'}, create a dictionary with the opposite mapping, i.e., write a program to create the dictionary as :
inverted_x = {'v1': 'k1' , 'v2' :'k2' , 'v3':'k3'}Given two dictionaries say D1 and D2. Write a program that lists the overlapping keys of the two dictionaries, i.e., if a key of D1 is also a key of D2, then list it.