Logical Practice Questions - ( DS140823 ) - 04-10-2023

Write below programs using pure logic and not even by taking inputs from user (no hardcoded values) :

  • Create Your own Dictionary Like This : d={1:2,2:3,3:4,4:5,5:6} Dictionary
  • Create Your own Dictionary Like This : d={2:4,3:6,4:8,5:10,6:12} Dictionary
  • Create Your own Dictionary Like This : d={2:4,4:8,6:12,8:16,10:20} Dictionary
  • Create Your own Dictionary Like This : d={1:1,2:8,3:27,4:64,5:125} Dictionary
  • Create Your own Dictionary Like This : d={5:15,7:21 ,9:27, 11:33 , 13:39}
#1. Create Your own Dictionary Like This : d={1:2,2:3,3:4,4:5,5:6} Dictionary

dict_comp = {i:(i+1) for i in range(1,6)}
print("d=",dict_comp,"Dictionary")


#2. Create Your own Dictionary Like This : d={2:4,3:6,4:8,5:10,6:12} Dictionary

dict_comp = {i:(i*2) for i in range(2,7)}
print("d=",dict_comp,"Dictionary")


#3. Create Your own Dictionary Like This : d={2:4,4:8,6:12,8:16,10:20} Dictionary

dict_comp = {i:(i*2) for i in range(2,11,2)}
print("d=",dict_comp,"Dictionary")


#4. Create Your own Dictionary Like This : d={1:1,2:8,3:27,4:64,5:125} Dictionary

dict_comp = {i:(i**3) for i in range(1,6)}
print("d=",dict_comp,"Dictionary")


#5. Create Your own Dictionary Like This : d={5:15,7:21 ,9:27, 11:33 , 13:39}

dict_comp = {i:(i*3) for i in range(5,14,2)}
print("d=",dict_comp)
1 Like
# 1]
myDict = {i: i + 1 for i in range(1,6)}
print ("d =",myDict)

# 2]
myDict = {i: i * 2 for i in range(2,7)}
print ("d =",myDict)

# 3]
myDict = {i: i * 2 for i in range(2,11,2)}
print ("d =",myDict)

# 4]
myDict = {i: i**3 for i in range(1,6)}
print ("d =",myDict)

# 5]
myDict = {i: i*3 for i in range(5,14,2)}
print ("d =",myDict)
1 Like
1.#Create Your own Dictionary Like This : d={1:1,2:8,3:27,4:64,5:125} Dictionary

dict_cube={1,2,3,4,5}

dict_cube={(i+1):(i+1)**3 for i in range(5)}

print("dict_cube value:=",dict_cube)

o/p:
dict_cube value:= {1: 1, 2: 8, 3: 27, 4: 64, 5: 125}

2.#Create Your own Dictionary Like This : d={2:4,3:6,4:8,5:10,6:12} Dictionary
dict_add={2,3,4,5,6}
dict_add={(i+2):(2*(i+2)) for i in range(6)}
print("dict_add of is:=",dict_add)
o/p:
dict_add of is:= {2: 4, 3: 6, 4: 8, 5: 10, 6: 12, 7: 14}

3.#Create Your own Dictionary Like This : d={2:4,4:8,6:12,8:16,10:20} Dictionary
dict_square={2,4,6,8,10}
dict_square={(i+2):(i+2)*(i+2) for i in range(5)} 
print("dict_square is:-",dict_square)
o/p:dict_square is:- {2: 4, 3: 9, 4: 16, 5: 25, 6: 36}

4.#Create Your own Dictionary Like This : d={5:15,7:21 ,9:27, 11:33 , 13:39}
dict_mul={5,7,9,11,13}
dic_mul={i:i*3 for i in range(5,14,2)}
print("dict_mul:=",dic_mul)
o/p:
dict_mul:= {5: 15, 7: 21, 9: 27, 11: 33, 13: 39}
1)
res ={i : i+1 for i in range(1,5+1)}

print(res)
2)
ressquare ={i : i*2 for i in range(2,6+1)}

print(ressquare)

3)
evensquare ={i : i*2 for i in range(2,10+1,2)}

print(evensquare)

4)
cube ={i : i**3 for i in range(1,5+1)}

print(cube)

5)
multiple ={i : i*3 for i in range(5,13+1,2)}

print(multiple)`

1 Like

Ans -

dict1 = {i:i+1 for i in range(1,6)}
print(f"Dictionary_1: {dict1}")

dict2 = {i:i*2 for i in range(2,7)}
print(f"Dictionary_2: {dict2}")

dict3 = {i:i*2 for i in range(2,11,2)}
print(f"Dictionary_3: {dict3}")

dict4 = {i:i**3 for i in range(1,6)}
print(f"Dictionary_4: {dict4}")

dict5 = {i:i*3 for i in range(5,14,2)}
print(f"Dictionary_5: {dict5}")
1 Like
dict1 = {i : (i+1) for i in range(1,6)}
print(f"d = {dict1}")

dict2 = {i : (2*i) for i in range(2,7)}
print(f"d = {dict2}")

dict3 = {i : (2*i) for i in range(2,11,2)}
print(f"d = {dict3}")

dict4 = {i : (i **3) for i in range(1,6)}
print(f"d = {dict4}")

dict5 = {i : (i * 3) for i in range(5,14,2)}
print(f"d = {dict5}")
1 Like
d1 = {i:i+1 for i in range(1,6)}
print(f"Dictionary_1: {d1}")

d2 = {i:i*2 for i in range(2,7)}
print(f"Dictionary_2: {d2}")

d3 = {i:i*2 for i in range(2,11,2)}
print(f"Dictionary_3: {d3}")

d4 = {i:i**3 for i in range(1,6)}
print(f"Dictionary_4: {d4}")

d5 = {i:i*3 for i in range(5,14,2)}
print(f"Dictionary_5: {d5}")
1 Like