Question

1. Assume that setA is a set that contains the following elements: 15, 1, 3, 8, 17, and 21. Assume that sets is a set that co

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Below is the detailed implementation of the above problem in PYTHON with code and output shown wherever neccessary.
  • For 1,
  • setA={15, 1, 3, 8, 17, 21} and setB={4,8,16,2,3,21}

a) setA ^ setB means that the elements which are not common in both will be in the resulting set i.e, {16, 1, 2, 17, 4, 15}. It means similar to Xor as Xor of 1 and 1 is 0 but Xor of ( 1 and 0 ) or ( 0 and 1 ) is 1.

>>> set([15, 1, 3, 8, 17, 21])*set([4,8,16,2,3,21]) {16, 1, 2, 17, 4, 15)

b) setA - setB means that those elements which are present in setB and setA too are deleted from setA, so this will result in {1, 17. 15}. It simply means that delete those elements from setA which are present in setB.

>>> set([15, 1, 3, 8, 17, 21])-set ([4,8,16,2,3,21]) {1, 17, 15)

c) setA.union(setB) means take the union of both the sets i.e, resulting set will contain all the elements of setA and setB i.e, {1, 2, 3, 4, 8, 15, 16, 17, 21}.

>>> set([15, 1, 3, 8, 17, 21]).union (set([4,8,16,2,3,21])) {1, 2, 3, 4, 8, 15, 16, 17, 21) >>>|

d) setA & setB means the common elements in both the set will be in our resulting set similar to logical and(&) operator which is 1 (when both a&b=1(when a=1 and b=1)). So result is  {8, 3, 21}.

>>> set([15, 1, 3, 8, 17, 21]) & set ([4,8,16,2,3,21]) {8, 3, 21) >>> |

  • For 2,
A B A or B not B (A or B) and (not B)
0 0 0 1 0
0 1 1 0 0
1 0 1 1 1
1 1 1 0 0
  • For 3,

a) on line 9 , = (assignment operator) assigns value returned by the function apple(10) to ls i.e, a list is assigned to ls as returned by apple() function.

b) on line 4 , ==(relational operator) is used to check if the operands on both sides are equal or not, if equal it returns True othewise False. So there it is checking if n is divisible by i or not.

c) On line 11 print(ls) will print list ls returned by apple(10) i.e,

[1, 2, 5, 10]

d)On line 12 print(len(ls)) will print length of list ls using len() function i.e, 4 as can be seen in the above list.

e) apple() function returns the list of integers which are divisors of n i.e, those integers i for which n%i=0.So it is used to find the divisor of a number n.

In [13]: def apple(n): fs=[] for i in range(1, n+1): if n%i==0: fs.append(i) return fs 1s-apple(10) print(15) print(len(15))

  • For 4,

If a programmer forgets to update the loop control variable in a while loop then the while loop will never terminate, for example:

#loop control variable
i=0
#while loop
while i<=10:
# updating loop control variable
i+=1

If line containing i+=1 is commented then you can see that condition of while loop will always be true so it will run forever without termination.

So if you still have any doubt regarding this solution please feel free to ask it in the comment section below and if it is helpful then please upvote this solution, THANK YOU.

Add a comment
Know the answer?
Add Answer to:
1. Assume that setA is a set that contains the following elements: 15, 1, 3, 8,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Complete the following case study: Case study: Three implementations of contains - comparing approaches to adding...

    Complete the following case study: Case study: Three implementations of contains - comparing approaches to adding functionality Set A contains Set B if every element in Set B is also in Set A. We will compare three ways to determine whether Set A contains Set B. Approach 1: Write code in the main method in a test class Add code to the main of ArraySetTester to create SetA and SetB, fill them with data and write a contains operation that...

  • question 1,7&10 a) Given the information below: {1, 2, 3, 4, 5, 6} A = {1}...

    question 1,7&10 a) Given the information below: {1, 2, 3, 4, 5, 6} A = {1} B= {4,5) C = {3,6} LIST the elements in each of the following sets: AU ( BCC) Hint Do not use ellipsis, but list each element of the set separated by a comma in numerical order in curly braces that look like this: {}. If the set is empty, type Empty Set without curly braces. (AUB) n(AUC) = Hint Do not use ellipsis, but...

  • S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write...

    S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write a program as a 3 or 5, and, raises to the power of 3 the elements that are script tile that doubles the elements that are positive and are divisible by negative but greater than -5. following values. The value of each element in the first row is the number of the 6. Write a program in a script file that creates an matrix...

  • 1) Using the periodic table only, arrange the elements in each set in order of increasing electronegativity. (a) Mg, P...

    1) Using the periodic table only, arrange the elements in each set in order of increasing electronegativity. (a) Mg, P, As (b) S, O, Si ....................................................................................................................................................... 2) Using the periodic table only, arrange the members of each of the following sets in order of increasing bond strength. (a) C=N, C-N, C N (b) S-H, S-Br, S-Cl (c) Br-Br, Cl-Cl, I-I ..................................................................................................................................... 3) Using the periodic table only, arrange the members of each of the following sets in order of increasing...

  • Plz i want answer these question using list in python programme. You are given two sequences...

    Plz i want answer these question using list in python programme. You are given two sequences of n integers: 21, 22, ...,an and b1,b2, ..., bn Print a sequence of 2n integers created by alternating elements from the given sequences: a1, 61, 42, 62, a3, 63, ..., an, bn. Input The first line contains a positive integer n (1 <n<1000) - the length of the sequences The second line contains n space-separated integers 01, 02, ..., an (-1000 <a; <...

  • Set up a vector n with elements 1, 2, 3, 4, 5. Use MATLAB array opera-...

    Set up a vector n with elements 1, 2, 3, 4, 5. Use MATLAB array opera- tions on it to set up the following four vectors, each with five elements: (a) 2, 4, 6, 8, 10 b)

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

  • 4. Consider the set A={{1, 2, 3}, {4,5}, {6,7,8}}. (a) What are the elements of A?...

    4. Consider the set A={{1, 2, 3}, {4,5}, {6,7,8}}. (a) What are the elements of A? (b) Determine whether each of the following is true or false, and explain why. i. 1 E A ii. {1,2,3} CA iii. {6,7,8} E A iv. {{4,5}} CA v. Ø & A vi. Ø CA

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : i have 15 min to submit the solution please help me   You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other...

  • Do the questions that are circled I need to double check my work first time learning this 12:22 For example, 12. 4. 1...

    Do the questions that are circled I need to double check my work first time learning this 12:22 For example, 12. 4. 121 could be written either (216andn eN) or 38 of 627 14.94 CHAPTER1 Sens, Proof Templanes, and Induction 3. Write three descriptions of the elements of the set (2, 5.8,11.14. How many elements does each of the following sets have e)E 1O, I.13.5). 14. 5,7).81 hich of the following pairs of sets are equal? For each find an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT