Skip to content

my-courses.net

Python Courses & Exercises

Facebook Twitter Google Plus Linkedin Instagram YouTube Pinterest Tumblr VK Email RSS
  • Home
  • Python Courses
  • Python Exercises
  • Computer Glossary
  • Register

Month: December 2022

Solution of Exercise 211: setof perfect square in python

December 16, 2022YOUNES DERFOUFIPython-ExercisesLeave a comment

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

December 15, 2022YOUNES DERFOUFIPython-ExercisesLeave a comment

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

December 15, 2022YOUNES DERFOUFIPython-ExercisesLeave a comment

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

December 14, 2022YOUNES DERFOUFIPython-ExercisesLeave a comment

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

December 14, 2022YOUNES DERFOUFIPython-ExercisesLeave a comment

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

December 14, 2022YOUNES DERFOUFIPython-ExercisesLeave a comment

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…

Search

Recent Posts

  • Solution Exercise 26: python algorithm to find all word beginning with the letter 'a'
  • Solution Exercise 25: python algorithm to reverse a given string
  • Solution Exercise 24: python program to check whether a word is palindrome or not
  • Solution Exercise 23: Python algorithm that extract the file extension
  • Solution Exercise 22: python algorithm that extract the first word in given text

Facebook Group

UserOnline

2 Users Online

Log In

3 × 1 =

  • Register
  • Lost your password?
© 2023 my-courses.net | Wordpress_Theme: Blogghiamo by CrestaProject.          CopyrightFrance.com