You are on page 1of 3

Q1)

records = {}

for _ in range(10):
roll_no = int(input("Enter roll number: "))
name = input("Enter name: ")
records[roll_no] = name

print(records)

Q2)

dict1 = {
1: "ABC",
2: "XYZ",
3: "MNO",
4: "GHI"
}

key = int(input("Enter a key: "))


if key in dict1:
print(f"Value: {dict1[key]}")
else:
print("Key not found in dictionary")

Q3)

records = {}
n = int(input("Enter number of records: "))

for _ in range(n):
roll_no = int(input("Enter roll number: "))
percentage = float(input("Enter percentage: "))
records[roll_no] = percentage

print("Students with percentage over 40:")


for roll_no in records:
if records[roll_no] > 40:
print(roll_no)
Q4)

def sum_of_cubes(l: list[int]):


res = 0
for i in l:
res += i ** 3
return res

arr = list(map(int, input().split()))


print(f"Sum of cubes: {sum_of_cubes(arr)}")

Q5)

def check_dict(d: dict):


values = d.values()
if len(values) != len(set(values)):
return {}
new = {}
for i in d:
new[d[i]] = i
return new

d = {
1: "hello",
2: "world"
}
print(d)
print(check_dict(d))

Q6)

import numpy as np

a1 = np.array([1, 4, 5, 8])
a2 = np.array([2, 3, 6, 8])

r = []
for i, j in zip(a1, a2):
if i > j:
r.append("GT")
elif i < j:
r.append("LT")
else:
r.append("EQ")

print(r)

Q7)

import numpy as np

a = np.random.randint(10, size=10)

print(f"Mean: {np.mean(a)}")
print(f"Median: {np.median(a)}")
print(f"Variance: {np.var(a)}")
print(f"Standard Deviation: {np.std(a)}")

You might also like