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
sdas [7]
3 years ago
14

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:
Assoli18 [71]3 years ago
4 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
If your body were a house, your skeleton would be the house's ___________.
frozen [14]
I think the answer is c wooden frame
3 0
3 years ago
Read 2 more answers
Assume that the int variables i, j and n have been declared , and n has been initialized . write code that causes a "triangle" o
SIZIF [17.4K]

Here you go,

class Program

   {

       static void Main(string[] args)

       {          

          int n,i,j;

          Console.Write("Enter size: ");

          n = Convert.ToInt32(Console.ReadLine());

          for (i = 1; i <= n; i++)

          {

              for (j = 1; j <= i; j++)

              {

                  System.Console.Write("*");

              }

              System.Console.Write("\n");

          }          

           Console.ReadLine();

       }

   }

5 0
3 years ago
An organization is assigned a Class-C network 200.120.80.0 and wants to form subnets for its threedepartments: D1 (60hosts), D2
Nataliya [291]

Answer:

D1= 60 HOSTS

network address - 200.120.80.64/26

subnet mask -255.255.255.192/26

D2 = 90 HOSTS

network address - 200.120.80.0/25

subnet mask -255.255.255.128/25

D3 = 90 HOSTS

network address - 200.120.80.128/25

subnet mask -255.255.255.128/25

5 0
4 years ago
In which tear was computer aided drafing invented
babymother [125]

Answer:

1957

Explanation:

4 0
4 years ago
The information computers give to users or other computers are called
AfilCa [17]

Answer:

the output processed data

7 0
2 years ago
Other questions:
  • How does a 3D CAD solid model program display the progression of work involved in creating a model?
    5·1 answer
  • Which two jobs have high demand need for practitioners( have a skill shortage)
    13·1 answer
  • A power supply unit for a computer converts:
    7·1 answer
  • What is a DreamScape?<br> Explain <br> and give example (if you want)
    10·1 answer
  • In excel, the applied theme has a set of complimentary ________, which are defined sets of formatting characteristics, such as f
    12·1 answer
  • Jim maintains attendance records for his employees for the year. Row B includes the dates of attendance, and column A includes t
    5·2 answers
  • Which of the following is not a reserved keyword in python?​
    13·1 answer
  • What year does futurist ray kurzweil believe ai will meet human intelligence?.
    7·2 answers
  • Sequence structure is when have a repetition of instructions. true false
    5·1 answer
  • When users connect to the network, they use a basic hardware terminal to access a desktop hosted on a virtualization server. wha
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!