Solution of Exercise 211: setof perfect square in python

Exercise 211 Write a Python program that returns the set of perfect square integers less than or equal to 100. Solution # function that tests if a number is a perfect squaredef perfectSquare(n): test=False for i in range(0 , n+1): # test if n is perfect square and change test to True if i**2 ==…

Solution Exercise 210: intersection and union of 3 python sets

Exercise 210 Resume the previous exercise (Exercise 209) without using the intersection() and union() methods. Solution A = {11, 21, 5, 7, 43, 32, 13, 9}B = {2, 19, 11, 33, 7, 25, 5, 4}C = {45,27,11,5,7,22,14,1}# Initialization of the intersection of the three setsI = set({})for x in A: if x in B and…

Solution Exercicse 209: Intersction and union of tree python sets

Exercise 209 Write a program in Python language that returns the intersection and the union of the following three sets: A = {11, 21, 5, 7, 43, 32, 13, 9}B = {2, 19, 11, 33, 7, 25, 5, 4}C = {45,27,11,5,7,22,14,1}   Solution A = {11, 21, 5, 7, 43, 32, 13, 9}B = {2,…

Solution Exercise 208: remove an element from a given python set

Exercise 208 Write a program in Python that remove an element from a given set A without using the discard() or remove() methods. Solution # define a set AA = { 'a', 'b', 'c', 'd' }# remove the 'd' element without using either the remove() method or the discard() method#initialize an empty set BB =…

Solution Exercise 207: add an element to a python set

Exercise 207 Given a set A = { 'a', 'b', 'c', 'd' }. Write an algorithm in Python that adds an element 'x' to A without using the add() method. Solution A = { 'a', 'b', 'c', 'd' }# we add 'x' to A via the union() methodA2 = A.union({'x'})# show set A2print(A2) # output:…

Solution Exercise 206: Symetric difference of two sets in python

Exercise206 Given two sets A = {'a' , 'b' , 'c' , 'd'} and B = {'c' , 'e' , 'd' , 'h'}. Write a Python program that returns their symmetric difference without using the python symmetric_difference() method. Solution A={'a', 'b', 'c', 'd'}B={'c', 'e', 'd', 'h'}# initialize symmetric differencesymmetric_diff = set({})# difference A - Bfor…