answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Elanso [62]
2 years ago
7

Write a function called add_tuples that takes three tuples, each with two values, and returns a single tuple with two values con

taining the sum of the values in the tuples. Test your function with the following calls:
print(add_tuples( (1,4), (8,3), (14,0) ))
print(add_tuples( (3,2), (11,1), (-2,6) ))
Note that these two lines of code should be at the bottom of your program. This should output

(23, 7)
(12, 9)

this is my output but I keep getting errors;
def add_tuples(tup):
add1= tup[0][0]+ tup[1][0] +tup[2][0]
add2= tup[0][1]+ tup[1][1] + tup[2][1]
return add1, add2
print(add_tuples( (1,4), (8,3), (14,0) ))
print(add_tuples( (3,2), (11,1), (-2,6) ))
Computers and Technology
1 answer:
Leni [432]2 years ago
4 0

In Python, tuples are indeed a data structure that also stores an ordered sequence of unchanging values, and following are the Python program to the given question:

Program Explanation:

  • Defining a method "add_tuples" that takes three variables "firstTuple, secondTuple, thirdTuple" into the parameter.
  • After accepting the parameter value a return keyword is used that adds a <em><u>single tuple with two values</u></em> and returns its value into the form of (x,y).
  • Outside the method, two print method is declared that calls the above method by passing value into its parameters.

Program:

def add_tuples(firstTuple, secondTuple, thirdTuple):#defining a method add_tuples that takes three variable in parameters

   return firstTuple[0]+secondTuple[0]+thirdTuple[0],firstTuple[1]+secondTuple[1]+thirdTuple[1] #using return keyword to add value

print(add_tuples((1,4), (8,3), (14,0)))#defining print method that calls add_tuples method takes value in parameters

print(add_tuples((3,2), (11,1), (-2,6)))#defining print method that calls add_tuples method takes value in parameters    

Output:

Please find the attached file.  

Learn more:

brainly.com/question/17079721

You might be interested in
Many people describe computers as “complex” machines. What can this mean
Mashcka [7]
''Why people describe computers as complex machines. A computer is a general purpose device that can be programmed to carry out a set of arithmetic or logical operations. [ Since a sequence of operations can be readily changed, the computer can solve more than one kind of problem. Modern computers based on integrated circuits are millions to billions of times more capable than the early machines, and occupy a fraction of the space.[2] Simple computers are small enough to fit into mobile devices, and mobile computers can be powered by small batteries. Personal computers in their various forms are icons of the Information Age and are what most people think of as “computers.” However, the embedded computers found in many devices from MP3 players to fighter aircraft and from toys to industrial robots are the most numerous.'' This was found on a unknown website.
5 0
2 years ago
Suppose you are given three data items that indicate a starting index in a list, an array of characters, and an array of link in
Artemon [7]

Answer:

see explaination

Explanation:

INCLUDE Irvine32.inc

;declare the variables

SPACE = 32

startIndex = 1

.data

statement BYTE "The correct sequence of array: ",0

; declare the chars('H','A','C','E','B','D','F','G')

chars BYTE 48h,41h,43h,45h,42h,44h,46h,47h

sizeOfArray = ($ - chars)

links DWORD 0,4,5,6,2,3,7,0

outputArray BYTE sizeOfArray DUP(?)

.code

main PROC

; assign starting index

mov eax,startIndex

; assign offset of array chars

mov ebx,OFFSET chars

; assign the size of the array

mov ecx, sizeOfArray

; assign the offset of array links

mov edi,OFFSET links

; assign the offset of new array

mov esi,OFFSET outputArray

; call the traverseLink procedure

call traverseLink

; display the characters of new array

mov edx,OFFSET statement

call writeString

; assign the offset of new array

mov esi,OFFSET outputArray

; assign the size of the array

mov ecx, sizeOfArray

; call the procedure printArray to print the ordered array

call printArray

exit

main ENDP

traverseLink PROC

forLoop:

; get the character at index eax

mov dl,[ebx+eax]

; assign it to new array

mov [esi] , dl

; get the value at the next index

mov eax,[edi+eax*4]

; goto next location of new array

inc esi

; repeat until ecx=0

loop forLoop

ret

traverseLink ENDP

printArray PROC

forLoop:

; get the character at index eax

mov al,[esi]

; print the character

call WriteChar

; increament esi to get next character

inc esi

; print the space character

mov al,SPACE

call WriteChar

loop forLoop

call Crlf

ret

printArray ENDP

END main

7 0
2 years ago
Given a sorted array of integer, A, with possible duplicate elements. Implement an efficient (sublinear running time complexity)
allsm [11]

Answer:

The java program is as follows.

import java.util.*;

import java.lang.*;

public class SearchProgram

{

   // sorted array may or may not containing duplicate elements

   static int A[] = {-1, 2, 3, 5, 6, 6, 6, 9, 10};

   

   // variable to keep track of number of occurrences, declared and initialized to 0

   static int times=0;

   

// variable to hold value to be searched in the array

   static int key;

   static int search(int[] art, int n)

   {

       // enhanced for loop used to find how many times n occurs in array, arr

       for(int j:arr)

       {

           if(n == j)

               times = times+1;

       }

       

       return times;

   }

   

   public static void main(String[] args)

   {

       // scanner object to allow user input

       Scanner sc = new Scanner(System.in);

       

       // user prompted to enter key to be searched

       System.out.print("Enter the element to be searched: ");

       key = sc.nextInt();

       

       // message displayed to the user on how many times the element is present in the array

       System.out.println("The element " + key + " is present " + search(A, key) + " times in the array.");

   

   }

}

OUTPUT

Enter the element to be searched: 3

The element 3 is present 1 times in the array.

Explanation:

The steps of program execution are shown below.

1. An integer array, A, is declared and initialized.

2. An integer variable, times, is declared and initialized to 0.

3. A method, search(), is created which takes 2 parameters, array A and user entered value for the element to be searched in A.

4. The search() method has return type of integer and returns the value of variable, times.

5. Inside the search() method, an enhanced for loop is used to compute the value of the variable, times.

6. In the main() method, user is prompted to enter the value of key.

7. The search() is called and value of the variable, times, displayed to the user.

8. All the methods and variables are declared as static.

7 0
2 years ago
Edhesive: Assignment 4: Evens and Odds
solniwko [45]

Answer:

Written in Python

n = int(input("How many numbers do you need to check? "))

odd = 0

even = 0

for i in range(1,n+1):

     num = int(input("Enter Number: "))

     if num%2 == 0:

           print(str(num)+" is an even number")

           even = even + 1

     else:

           print(str(num)+" is an odd number")

           odd = odd + 1  

print("You entered "+str(even)+" even number(s).")

print("You entered "+str(odd)+" odd number(s).")

Explanation:

<em>I've added the full source code as an attachment where I use comments (#) as explanation</em>

Download txt
6 0
2 years ago
Write a program whose input is two integers. Output the first integer and subsequent increments of 10 as long as the value is le
kotykmax [81]

The answer & explanation for this question is given in the attachment below.

8 0
2 years ago
Other questions:
  • Enter a formula in cell G5 that calculates the difference between the attendance totals for 2018 and 2017. Copy the formula to t
    6·1 answer
  • You are the administrator for the contoso.com website. recently, the server hosting the website had a failure that caused it to
    13·1 answer
  • A mistake programmers often make with loops is that they ____.
    15·1 answer
  • Problem 1a. Write a function named hasFinalLetter that takes two parameters 1. strList, a list of non-empty strings 2. letters,
    8·1 answer
  • Write a code segment that uses an enhanced for loop to print all elements of words that end with "ing". As an example, if words
    6·1 answer
  • You cannot change data directly in the PivotTable. Instead, you must edit the Excel table, and then ____, or update, the PivotTa
    9·2 answers
  • Which of the following option is correct about HCatalog?
    14·1 answer
  • Select the correct answer. Andy wants to become a multimedia producer. Which degree can help him achieve this goal? A. bachelor’
    5·1 answer
  • Ishaan is confused between the terms webpage and website help him in understanding the difference between both​
    11·1 answer
  • "There are no longer mature industries; rather, there are mature ways of doing business," he is referring to the high demand of
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!