Skip to content

Commit 9067da3

Browse files
authored
Update Dictionary-Questions.py
1 parent e08d28c commit 9067da3

File tree

1 file changed

+50
-52
lines changed

1 file changed

+50
-52
lines changed

Dictionary-Questions.py

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@
7878
print(str(i)+"'s highest mark is "+str(max(d[i])))
7979

8080
# 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={}
8383
for i in range(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=[]
8787
for j in range(ns):
88-
stop = input("What is stop "+str(j+1)+"? ")
88+
stop=input("What is stop "+str(j+1)+"? ")
8989
sl.append(stop)
9090
d[tn]=sl
9191
for i in d:
@@ -95,75 +95,75 @@
9595
pass
9696

9797
# 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={}
100100
for i in range(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=""
107107
for j in d:
108108
if d[j][1]>high:
109-
high = d[j][1]
110-
highn = j
109+
high=d[j][1]
110+
highn=j
111111
print("Max selling price is:",high)
112-
low = d[item][1]
113-
lown = ""
112+
low=d[item][1]
113+
lown=""
114114
for k in d:
115115
if d[k][1]<low:
116-
low = d[k][1]
117-
lown = k
116+
low=d[k][1]
117+
lown=k
118118
print("Min selling price is:",low)
119119

120120
# 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? "))
123123
for i in range(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])
131131
print(Ds)
132132

133133
# 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.
134-
d = {}
134+
d={}
135135
for i in range(n):
136-
examno = int(input("Exam number: "))
137-
name = input("Name: ")
138-
clas = int(input("Class: "))
139-
gender = input("Gender: ")
140-
d[examno] = {"Name":name,"Class":clas,"Gender":gender}
136+
examno=int(input("Exam number: "))
137+
name=input("Name: ")
138+
clas=int(input("Class: "))
139+
gender=input("Gender: ")
140+
d[examno]={"Name":name,"Class":clas,"Gender":gender}
141141
for j in d:
142142
if d[j]["Class"]==11:
143143
print(str(j)+":"+str(d[j]))
144144

145145
# 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? "))
148148
for i in range(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: "))
156156
Ds[examno]=[name,[m1,m2,m3,m4,m5]]
157157
print(Ds)
158158
def avg(l):
159-
av = sum(l)/len(l)
159+
av=sum(l)/len(l)
160160
return av
161-
high = 0
162-
highn = ""
161+
high=0
162+
highn=""
163163
for k in Ds:
164164
if avg(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]
167167
else:
168168
pass
169169
print()
@@ -172,9 +172,7 @@ def avg(l):
172172
# 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.
173173
n = int(input("The number of students: "))
174174
print("Vote for student a or b or c: ")
175-
a = 0
176-
b = 0
177-
c = 0
175+
a,b,c=0,0,0
178176
for i in range(n):
179177
vote = input("The vote of student "+str(i+1)+": ")
180178
if vote == "a" or vote == "A":

0 commit comments

Comments
 (0)