Professional Documents
Culture Documents
ENROLL-2019BITE045
Output:
Q2.WAP to swap two numbers without using third variable.
CODE:
a=int(input("Enter first number"))
b=int(input("Enter second number"))
a,b=b,a
print("Numbers after swapping are:"+str(a)+","+str(b))
OUTPUT:
CODE:
import array as ar
a=ar.array('i',[21,14,17,90])
print("sum of array is:",sum(a))
OUTPUT:
OUTPUT:
Q5.WAP to replace multiple words with K.
CODE:
test_string = 'Welcome to the world of python '
print("The original string is : " + str(test_string))
OUTPUT:
Q6.WAP to replace all occurrences of a substring in a string.
CODE:
string_a = "The brown coloured car is actually owned by a brown-eyed man."
string_b = string_a.replace("brown", "blue")
print(string_a)
print(string_b)
OUTPUT:
Q7.Sort python Dictionaries by Key or Value.
CODE:
def dictionairy():
key_value = {}
key_value[2] = 56
key_value[1] = 2
key_value[5] = 12
key_value[4] = 24
key_value[6] = 18
key_value[3] = 323
for i in sorted(key_value):
print((i, key_value[i]), end=" ")
def main():
dictionairy()
if __name__ == "__main__":
main()
OUTPUT:
CODE:
test_dict = {"Aru": 25, "Anu": 21, "Mani": 21, "Haritha": 21}
OUTPUT:
Q9.Sort python dictionaries by key or value.
CODE:
def dictionairy():
key_value = {}
key_value[2] = 562
key_value[1] = 2
key_value[5] = 1
key_value[4] = 24
key_value[6] = 18
key_value[3] = 323
print(sorted(key_value.items(), key=
lambda kv: (kv[1], kv[0])))
def main():
dictionairy()
if __name__ == "__main__":
main()
OUTPUT:
Q10.Check if binary representation of two numbers is
anagram.
CODE:
SIZE = 8
global size
i = 0
binary_a = [0] * SIZE
while (a > 0):
binary_a[i] = a % 2
a //= 2
i += 1
j = 0
binary_b = [0] * SIZE
while (b > 0):
binary_b[j] = b % 2
b //= 2
j += 1
binary_a.sort()
binary_b.sort()
for i in range(SIZE):
if (binary_a[i] != binary_b[i]):
return 0
return 1
if __name__ == "__main__":
a = 8
b = 4
print(bit_anagram_check(a, b))
OUTPUT: