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]
2 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]2 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
Write the code to compute and output how many times the value 99 is found in an array of integers named numbers
astraxan [27]
Thank you for being the rare question where you actually provide what language you want your answer in; I approve, and encourage this.

In Java, the following will work.
I made it a bit more versatile to work with others numbers, other than 99, if you so please (if not, just hardcode the 99 in yourself).

// Example list - fill this with numbers yourself.
ArrayList<Integer> nums = new ArrayList<>();
int n = 99;
int count = (int)nums.stream().filter(i -> i == n).count();
System.out.println(n + " occurences.");
8 0
3 years ago
Data entry is the process of getting information into a database. true false
Keith_Richards [23]
Yes it's the process of entering data into a database.
6 0
3 years ago
Read 2 more answers
Task 1 – File Input
e-lub [12.9K]

Answer:

Check the explanation

Explanation:

using System;

using System.IO;

                 

public class Program

{

 

  public static void Main()

  {

      string[] lines;

      Console.WriteLine("enter name of the file");

      String fileName=Console.ReadLine();

     

      Console.WriteLine("enter path of the file");

      String filePath=Console.ReadLine();

     

      using (StreamReader streamReader = File.OpenText(filePath))

      {

          String text = streamReader.ReadToEnd();

          lines = File.ReadAllLines(filePath);

      }

      Console.WriteLine("Enter path of the file to write");

      String outputFilePath = Console.ReadLine();

      bool fileExist = File.Exists(outputFilePath);

      if (fileExist)

      {      

                  overWriteOrChangeFileName(outputFilePath);          

      }

      else

      {

          File.Create(outputFilePath);

          File.WriteAllLines(outputFilePath, lines);

      }

      Console.Write("Input file Path"+filePath);

      Console.Write("output file path"+outputFilePath);

     

      void overWriteOrChangeFileName(String filePathtoCheck){

          Console.WriteLine("File exists. Do you want to overwrite the file or do you want to change the location and file name of the new file.Press Y to overwrite and press C to change the location and filename");

          String userInput=Console.ReadLine();

          if(userInput.Equals("Y")){

File.WriteAllLines(outputFilePath, lines);

          }else{

              Console.WriteLine("enter new path of the file including filename");

              String NewFileName=Console.ReadLine();

              outputFilePath=NewFileName;

              if(File.Exists(outputFilePath)){

                  overWriteOrChangeFileName(outputFilePath);                  

              }

              else

      {

          File.Create(outputFilePath);

          File.WriteAllLines(outputFilePath, lines);

      }

          }

      }

  }

 

}

3 0
3 years ago
Linguist study_____
-Dominant- [34]
That's B.

Linguist love all kinds of studies of languages culture writing etc.
6 0
2 years ago
PLEASE HELP, THANK YOU SO MUCH!
ozzi

Answer:

The correct answer is "Once a day".

Explanation:

According to social media marketing, it is a good idea to check your reader at least once a day. Readers help business by tracking what the consumers are seeing and what times of the day. Checking the reader at least once a day help people in marketing to be updated, because people's preference keep changing all the time.

3 0
3 years ago
Other questions:
  • What are the basic tools for coding HTML manually?
    10·2 answers
  • One study found that nearly ____________ of the 1600 college freshmen surveyed had sent sexually suggestive texts or photos.
    11·1 answer
  • How do you represent images in binary
    6·2 answers
  • Write a generator function named count_seq that doesn't take any parameters and generates a sequence that starts like this: 2, 1
    7·1 answer
  • Find a 95% confidence interval for the mean failure pressure for this type of roof panel.The article "Wind-Uplift Capacity of Re
    7·1 answer
  • Abby wants to simply share a snapshot of her calendar with another user. Which option should she choose to achieve
    15·1 answer
  • Sistem komponen mekanikal yang terdapat pada sebuah basikal?​
    13·1 answer
  • Define the terms network, LAN, WAN, and Internet.
    11·1 answer
  • What is a for command? can u use a variable instead of a number in the for command!<br>​
    14·1 answer
  • What is multimedia hard ware? Write any four examples of multimedia hardware. <br>​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!