Question

use the function design recipe from chapter 3 of practical programming to develop a function named...

use the function design recipe from chapter 3 of practical programming to develop a function named sum_x. the function takes a set of n points: { (x0 , y0 ), (x1 , y1 ), … (xn-1 , yn-1 ) }. each point is represented by a tuple containing two floats. the first and second floats are the point's x and y coordinates, respectively. the function returns the sum of all the x coordinates: x0 + x1 + x2 + … + xn-1 .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

The solution to the given problem is provided using functions as shown below.

In order to show the functionality of code, the sample set is created with tuples in it and the output is attached to it.

Code:

def sum_x(s): #function to calculate the sum of x-coordinates
sum=0.0
for i in s: #for every tuple in set, get x value and add it to sum value
sum+=i[0]
return sum #Return sum

s={(2.5,3.2),(2.7,5.2),(2.6,5.1)} #set initialized with tuples
print("The sum of x co-ordinates is :",sum_x(s)) #print the result

Screenshot:

The screenshots are provided with the output for reference. Please follow them.

Add a comment
Know the answer?
Add Answer to:
use the function design recipe from chapter 3 of practical programming to develop a function named...
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
  • In Python use the function design recipe from Chapter 3 of Practical Programming to develop a...

    In Python use the function design recipe from Chapter 3 of Practical Programming to develop a function named first_last6. The function takes a list of integers. (Assume that the list will not be empty.) The function returns True if a 6 is the first element or the last element or if both the first and last element are 6. Otherwise, the function returns False.

  • I really need help with this python programming assignment Program Requirements For part 2, i need...

    I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n):   lst = []   for i in range(1,n+1):     val = float(input('Enter float '+str(i)+': '))     lst.append(val)   return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...

  • Please use DrRacket Programming Write a structurally recursive function named (tails lst) that takes a list...

    Please use DrRacket Programming Write a structurally recursive function named (tails lst) that takes a list as an argument and returns all the sublists of the list. For example: > (tails '(1 2 3)) '((1 2 3) (2 3) (3) ()) > (tails '((a b) (c d))) '(((a b) (c d)) ((c d)) ()) Think carefully about what the function should return if it receives the empty list as an argument. Finish this template: (define tails (lambda (lst)

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials....

    Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials. Download the template for function lagrange interp.m. The tem Plate is in homework 4 folder utl TritonED·TIue function lakes in the data al nodex.xi and yi, as well as the target x value. The function returns the interpolated value y. Here, xi and yi are vectors while x and y are scalars. You are not required to follow the template; you can create the...

  • Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code. Your task is to implement this algorithm in Python, returning a random collection of...

    Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code. Your task is to implement this algorithm in Python, returning a random collection of inum-100, 000 points. You should then plot the points to see the structure. Please complete the following function: def sierpinski (po, v, f, inum) The four arguments are ·po the initial point. You may assume this is the origin, i.e., po = [0, 0] . v:...

  • I am programing an Extended Kalman Filter , with noise but not getting correct answer ....

    I am programing an Extended Kalman Filter , with noise but not getting correct answer . this is my code # ---------- # Part Two # # Now we'll make the scenario a bit more realistic. Now Traxbot's # sensor measurements are a bit noisy (though its motions are still # completetly noise-free and it still moves in an almost-circle). # You'll have to write a function that takes as input the next # noisy (x, y) sensor measurement and...

  • C++ Programming - Design Process I need to create a flow chart based on the program...

    C++ Programming - Design Process I need to create a flow chart based on the program I have created. I am very inexperienced with creating this design and your help will be much appreciated. My program takes a string of random letters and puts them them order. Our teacher gave us specific functions to use. Here is the code: //list of all the header files #include <iomanip> #include <iostream> #include <algorithm> #include <string> using namespace std; //Here are the Function...

  • Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....

    Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you. Phase 1 You must design 3 algorithms, and provide both a flow chart and pseudo code for the algorithms.    Algorithm descriptions: Given an integer parameter named current_number and two constant global variables: const int MIN_NUMBER = 1; const int MAX_NUMBER = 8; Create an algorithm named forward, that will advance ONE value through a sequence of numbers 1, 2, 3 ... MAX_NUMBER. In...

  • please answer the second part first part answered. the answer to the first part is at...

    please answer the second part first part answered. the answer to the first part is at the bottom bring the rest of the place HAVE TO BE SOLVED WİTH C PROGRAMMİNG A programming task is given in below (i.e., you are supposed to write a single program involving all 5 tasks in below). You should write a C program and upload your c/cpp file . Students are allowed to use MAK104E course (powerpoint) slights. 1) Three geometric entities (a circle,...

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