DSE Lab Assignment 01.ipynb
DSE Lab Assignment 01.ipynb
ipynb - Colaboratory
ROLL NO. - 21
BATCH - F
Q 1. Write a python program to create a dictionary which contains student’s names and marks. Iterate over the
dictionary and apply below conditions to print their grades: a. Marks greater than or equal to 70 – Distinction b.
Marks between 60-69 – First Class c. Marks between 50-59 – Second Class d. Marks between 40-49 –Pass e.
Marks less than 40 - Fail
students = dict()
n = int(input("Enter Number of Students : ")) #taking input from user
for i in range(n): #running for loop for n inputs
sname = input("Enter Name of Student : ")
mark = int(input("Enter Marks : "))
students[sname] = mark
print("\nDictionary of Student Created :")
print(students)
for i,j in students.items(): #i for name & j for marks
if j<40:
print("")
print(i,'- Fail',[j])
elif j in range(40,50): # 50 is excluded
print("")
print(i,'- Pass',[j])
elif j in range(50,60): # 60 is excluded
print("")
print(i,'- Second Class',[j])
elif j in range(60,70): #70 is excluded
print("")
print(i,'- First Class',[j])
elif j>=70:
print("")
print(i,'- Distinction',[j])
Enter Marks : 92
Enter Marks : 68
Enter Marks : 54
Enter Marks : 44
Enter Marks : 26
Enter Marks : 70
{'Ram': 92, 'Akshat': 68, 'Abhishek': 54, 'Nitish': 44, 'John': 26, 'Harry': 70}
https://colab.research.google.com/drive/1CsiBVuHx9moFuQp6r8usQpnipnOVozBC#scrollTo=c37P-dr38ZR7&printMode=true 1/2
8/27/22, 11:02 PM DSE Lab Assignment 01.ipynb - Colaboratory
Nitish - Pass [44]
import numpy as np
array = np.array([i for i in range(10)]) #add i in the array till it satisfy the range condition
print(array)
[0 1 2 3 4 5 6 7 8 9]
# OR WE CAN ALSO USE THIS METHOD
import numpy as np
y=np.arange(0,10) # 10 will be excluded
print(y)
[0 1 2 3 4 5 6 7 8 9]
Q 3. Write a NumPy program to create a 3x4 matrix filled with values from 10 to 21.
import numpy as np
n=np.arange(10,22).reshape(3,4) # 22 will be excluded and 3 & 4 are no. of rows & columns respectively
print(n)
[[10 11 12 13]
[14 15 16 17]
[18 19 20 21]]
https://colab.research.google.com/drive/1CsiBVuHx9moFuQp6r8usQpnipnOVozBC#scrollTo=c37P-dr38ZR7&printMode=true 2/2