You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Dictionary-Questions.py
+50-52Lines changed: 50 additions & 52 deletions
Original file line number
Diff line number
Diff line change
@@ -78,14 +78,14 @@
78
78
print(str(i)+"'s highest mark is "+str(max(d[i])))
79
79
80
80
# Create a dictionary with n train numbers as key and value is a list of all stops. Print the train numbers which has a stop at Chennai.
81
-
n=int(input("How many trains? "))
82
-
d={}
81
+
n=int(input("How many trains? "))
82
+
d={}
83
83
foriinrange(n):
84
-
tn=int(input("Input the train number: "))
85
-
ns=int(input("Number of stops: "))
86
-
sl=[]
84
+
tn=int(input("Input the train number: "))
85
+
ns=int(input("Number of stops: "))
86
+
sl=[]
87
87
forjinrange(ns):
88
-
stop=input("What is stop "+str(j+1)+"? ")
88
+
stop=input("What is stop "+str(j+1)+"? ")
89
89
sl.append(stop)
90
90
d[tn]=sl
91
91
foriind:
@@ -95,75 +95,75 @@
95
95
pass
96
96
97
97
# Create a dictionary with n items name as key and value will be a tuple with cp and sp and print the item name with maximum sp and minimum sp
98
-
n=int(input("How many items? "))
99
-
d={}
98
+
n=int(input("How many items? "))
99
+
d={}
100
100
foriinrange(n):
101
-
item=input("Input name of item: ")
102
-
cp=eval(input("Cost Price: "))
103
-
sp=eval(input("Selling Price: "))
104
-
d[item]=(cp,sp)
105
-
high=0
106
-
highn=""
101
+
item=input("Input name of item: ")
102
+
cp=eval(input("Cost Price: "))
103
+
sp=eval(input("Selling Price: "))
104
+
d[item]=(cp,sp)
105
+
high=0
106
+
highn=""
107
107
forjind:
108
108
ifd[j][1]>high:
109
-
high=d[j][1]
110
-
highn=j
109
+
high=d[j][1]
110
+
highn=j
111
111
print("Max selling price is:",high)
112
-
low=d[item][1]
113
-
lown=""
112
+
low=d[item][1]
113
+
lown=""
114
114
forkind:
115
115
ifd[k][1]<low:
116
-
low=d[k][1]
117
-
lown=k
116
+
low=d[k][1]
117
+
lown=k
118
118
print("Min selling price is:",low)
119
119
120
120
# Create a dictionary with n students name as key and value is a list of 5 marks. Change the dictionary such that the value will be a list in ascending order
121
-
Ds={}
122
-
n=int(input("How many students? "))
121
+
Ds={}
122
+
n=int(input("How many students? "))
123
123
foriinrange(n):
124
-
name=input("The name of student: ")
125
-
m1=int(input("Marks of Subject 1: "))
126
-
m2=int(input("Marks of Subject 2: "))
127
-
m3=int(input("Marks of Subject 3: "))
128
-
m4=int(input("Marks of Subject 4: "))
129
-
m5=int(input("Marks of Subject 5: "))
130
-
Ds[name]=sorted([m1,m2,m3,m4,m5])
124
+
name=input("The name of student: ")
125
+
m1=int(input("Marks of Subject 1: "))
126
+
m2=int(input("Marks of Subject 2: "))
127
+
m3=int(input("Marks of Subject 3: "))
128
+
m4=int(input("Marks of Subject 4: "))
129
+
m5=int(input("Marks of Subject 5: "))
130
+
Ds[name]=sorted([m1,m2,m3,m4,m5])
131
131
print(Ds)
132
132
133
133
# Create a dictionary with exam number as key and value is another dictionary with name, class and gender and print key and values if class is 11.
# Create a dictionary with key as exam no and value is a dictionary with name, mark which is a list of 5 marks. Print the roll no and name of the student getting rank 1
146
-
Ds={}
147
-
n=int(input("How many students? "))
146
+
Ds={}
147
+
n=int(input("How many students? "))
148
148
foriinrange(n):
149
-
examno=int(input("The exam number of student "+str(i+1)+": "))
150
-
name=input("The name of student "+str(examno)+" : ")
151
-
m1=int(input("Marks of Sbuject 1: "))
152
-
m2=int(input("Marks of Sbuject 2: "))
153
-
m3=int(input("Marks of Sbuject 3: "))
154
-
m4=int(input("Marks of Sbuject 4: "))
155
-
m5=int(input("Marks of Sbuject 5: "))
149
+
examno=int(input("The exam number of student "+str(i+1)+": "))
150
+
name=input("The name of student "+str(examno)+" : ")
151
+
m1=int(input("Marks of Sbuject 1: "))
152
+
m2=int(input("Marks of Sbuject 2: "))
153
+
m3=int(input("Marks of Sbuject 3: "))
154
+
m4=int(input("Marks of Sbuject 4: "))
155
+
m5=int(input("Marks of Sbuject 5: "))
156
156
Ds[examno]=[name,[m1,m2,m3,m4,m5]]
157
157
print(Ds)
158
158
defavg(l):
159
-
av=sum(l)/len(l)
159
+
av=sum(l)/len(l)
160
160
returnav
161
-
high=0
162
-
highn=""
161
+
high=0
162
+
highn=""
163
163
forkinDs:
164
164
ifavg(Ds[k][1])>high:
165
-
high=avg(Ds[k][1])
166
-
highn=Ds[k][0]
165
+
high=avg(Ds[k][1])
166
+
highn=Ds[k][0]
167
167
else:
168
168
pass
169
169
print()
@@ -172,9 +172,7 @@ def avg(l):
172
172
# Voting details should be available in a dictionary in the format key will be roll number and value the name of student voted for and declare the winner.
0 commit comments