1answer.
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
Komok [63]
3 years ago
9

Write a function square_evens(values) that takes a list of integers called values, and that modifies the list so that all of its

even elements are replaced with their squares, but all of its odd elements are left unchanged.
Computers and Technology
1 answer:
Mice21 [21]3 years ago
5 0

Answer:

#create the function

def square_evens(values):

   count_Value = 0

   #loop loop for iteration

   for i in values:

       #check for even number

       if (i) % 2 == 0:

           values[count_Value] = i * i  #store the square in the same index

       count_Value =count_Value + 1

   print(values)  #print the list

# list of integers

values = [1, 2, 3, 4, 5, 6]

#calling the function

square_evens(values)

Explanation:

The above code is written in python. first, create the function square_evens() which takes one parameter of the list.

inside the function declare the variable and then take a for loop for traversing each element in the list. Inside the for loop, we take the if-else statement for checking the number is even. if the number is even then stored the square of that value in the same list. To store the square value in the same index, we take the count variable for tracking the index.

After the all element in the list checked, the program terminates the loop and then print the updated list on the screen.

Outside the function, create the list with an integer value and then calling the function with passing the list argument.  

NOTE: In the python programming, please keep the indentation in code.

You might be interested in
A supermarket chain wants you to implement an in-memory database that can be used to access facts about the products they sell.
victus00 [196]

Answer:

D) They want to be able to increase the size of the database- adding large sets of new record - without taking the system offline.

Explanation:

The in memory is used in database to increase the storage size. In memory database management system primarily relies on the main memory. All the data will be stored and managed on the main memory. This is used in the systems where there is need for data access for large files, There can be many risks associated with this setup which can even lead to server failure.

5 0
3 years ago
Every brand of computer has its own binary language, called
Kaylis [27]
Machine language.

Hope this helps
6 0
3 years ago
Write a function that takes as input a single parameter storing a list of integers and returns the minimum, maximum, and average
Alex Ar [27]

Answer:

hi im coolkid 1000

Explanation:

just 5 robuk

6 0
3 years ago
Write the definition of a method named add that receives a reference to a Scanner object associated with a stream of input consi
Lisa [10]

Answer:

import java.util.*;

class Main  

{

   public static void main(String[] args)

   {

       System.out.println("Enter integers and 0 to exit");

       Scanner a1=new Scanner(System.in);

       System.out.println(add(a1));

       

   }

  public static int add(Scanner a1)

  {

        int total = a1.nextInt();

          if (a1.hasNextInt())

              {

                 total =total +add(a1);

              }

       return total;

   }

}

Explanation:

The only thing that needs explanation here is hasnextInt. This returns true if entered number is integer and false if entered is not an integer. And rest is as shown in the program.

5 0
4 years ago
Define a method named swapValues that takes an array of four integers as a parameter, swaps array elements at indices 0 and 1, a
Luba_88 [7]

The program is an illustration of arrays.

Arrays are used to hold multiple values.

The program in java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main{

   //This defines the method

public static int[] swapValues(int[] arr) {

   //This swaps the first and second array elements

       int temp = arr[0];

       arr[0] = arr[1];   arr[1] = temp;

   //This swaps the third and fourth array elements

       temp = arr[2];

       arr[2] = arr[3];   arr[3] = temp;

   //This returns the swapped array to main

       return arr;

}

//The main method begins here

   public static void main(String[] args) {

       //This creates a Scanner object

       Scanner input = new Scanner(System.in);

 //This declares an array of 4 elements

 int[] intArray = new int[4];

 //This gets input for the array

 for(int i = 0; i<4;i++){

     intArray[i] = input.nextInt();

 }

 //This calls the swapValues method

 intArray=swapValues(intArray);

 //This prints the swapped array

 for (int i = 0; i < 4; i++){

 System.out.print( intArray[i]+ " ");     }

}  

}

At the end of the program, the elements are swapped and printed.

Read more about similar programs at:

brainly.com/question/14017034

6 0
3 years ago
Other questions:
  • What is the central unit of the computer that contains the logic circuitry and carries out the instructions of the computer's pr
    13·1 answer
  • Why is ipsec considered to be a transparent security protocol?
    6·1 answer
  • Se citește un număr natural n cu cel mult 16 cifre. Fie q numărul de cifre ale numărului n. Prin eliminarea unei singure cifre d
    5·1 answer
  • A field with the ____ data type can store a unique sequential number that Access assigns to a record. Access will increment the
    7·1 answer
  • When would it be beneficial to make a copy of a document
    10·1 answer
  • Python program
    9·1 answer
  • Someone, please help me w/ king.com
    10·1 answer
  • Can’t be opened because apple cannot check it for malicious software.
    15·1 answer
  • In python, what is the difference between a dictionary and a set? How are they similar?
    11·1 answer
  • Which item is developed last in the cyclical process?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!