Exercise 3 Step 1: When you read Storing Data Using Sets, you learned that Python's set type allows...

60.1K

Verified Solution

Question

Programming

Exercise 3

Step 1:

When you read Storing Data Using Sets, you learned that Python'sset type allows us to create mutable collections of unordereddistinct items. The items stored in a set must be immutable, sosets can contain values of type int, float or str, but we can'tstore lists or sets in sets. Tuples are immutable, so we can storetuples in sets. Try this experiment, which creates a set containingthe points (1.0, 2.0), (4.0, 6.0) and (10.0, -2.0). What isdisplayed when points is evaluated? Write the question and theanswer in lab11.py using python comments. >>> points ={(1.0, 2.0), (4.0, 6.0), (10.0, -2.0)} >>> points We canalso initialize the set this way. Try this experiment. What isdisplayed when points is evaluated? Write the question and theanswer in lab11.py using python comments. >>> point1 =(1.0, 2.0) >>> point2 = (4.0, 6.0) >>> point3 =(10.0, -2.0) >>> points = {point1, point2, point3}>>> points We could instead start with an empty set, andcall the add method to initialize it, one point at a time. Try thisexperiment. What is displayed when points is evaluated? Write thequestion and the answer in lab11.py using python comments.>>> points = set() >>> points.add(point1)>>> points.add(point2) >>> points.add(point3)>>> points

Step 2:

What happens if we try to insert a point that is already in theset? Try this experiment: >>> points.add(point2)>>> points How many copies of point (4.0, 6.0) are in theset? Write the question and the answer in lab11.py using pythoncomments.

Step 3:

Can individual points in the set be retrieved by specifying anindex (position)? Try this experiment. What is displayed whenpoints[0] is evaluated? Write the question and the answer inlab11.py using python comments. >>> points[0]

Step 4:

We can use a for loop to iterate over all the points in the set.What is displayed when this loop is executed? Write the questionand the answer in lab11.py using python comments. >>> forpoint in points: ... print(point) ...

Answer & Explanation Solved by verified expert
3.7 Ratings (642 Votes)
Answerlab11pystep 1case 1 When Point is evaluated it givespoint1020406010020Ans When point is evaluated it gives10 20 100 20 40 60case 2 point11020point24060point310020pointspoint1point2point3Ans When point    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students