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
murzikaleks [220]
3 years ago
11

#Write a function called alter_list. alter_list should have#two parameters: a list of strings and a list of integers.##The list

of integers will represent indices for the list of#strings. alter_list should alter the capitalization of all#the words at the designated indices. If the word was all#capitals, it should become all lower case. If it was all#lower case, it should become all capitals. You may assume#that the words will already be all-caps or all-lower case.##For example:## string_list = ["hello", "WORLD", "HOW", "are", "you"]# index_list = [0, 2]# alter_list(string_list, index_list) -> # ["HELLO", "WORLD", "how", "are", "you"]##After calling alter_list, the strings at indices 0 and 2#have switched their capitalization. ##Note that it may be the case that the same index is present#in the second twice. If this happens, you should switch the#text at that index twice. For example:## string_list = ["hello", "WORLD", "HOW", "are", "you"]# index_list = [0, 2, 2]# alter_list(string_list, index_list) -> # ["HELLO", "WORLD", "HOW", "are", "you"]##2 is in index_list twice, so the string at index 2 is#switched twice: capitals to lower case, then back to#capitals.#Write your function here!#Below are some lines of code that will test your function.#You can change the value of the variable(s) to test your#function with different inputs.##If your function works correctly, this will originally#print:#["hello", "WORLD", "HOW", "are", "you"]#["HELLO", "WORLD", "HOW", "are", "you"]print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2]))print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2, 2]))
Computers and Technology
1 answer:
Aleks04 [339]3 years ago
7 0

Answer:

The Python code is given below with appropriate comments

Explanation:

def alter_list(strings,index):

   

   for i in index:

       s = strings[i]

       if s.islower():  #checking if lowercase

           strings[i] = s.upper()  #assigning variable in strings to uppercase in s

           

       if s.isupper():  #checking if uppercase

           strings[i] = s.lower()  #assigning variable in strings to lowercase in s

   return strings  #returns strings for the function

           

print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2]))

print(alter_list(["hello", "WORLD", "HOW", "are", "you"], [0, 2, 2]))

You might be interested in
As we think of computer crime, there are ways in which thieves can steal your banking information through ATM machines. If you w
Travka [436]

Answer:NO, I WILL NOT GIVE THE TELEPHONE NUMBER

WHY?

IT IS A BREACH OF TRUST

IT IS A BREACH OF DATA PRIVACY

IT ALSO VIOLATES THE PRIVACY OF INFORMATION RIGHT OF THE GIRL.

Explanation:BREACH OF TRUST is act or actions taken against the signed agreement between a person and another party which may be any Organisation like a Financial Institution where the Financial Institution agrees not to release the personal Information about their customer without the person's consent.

IT IS A BREACH OF DATA PRIVACY many persons wants their data which are made available to Organisation to be kept private,divulging such information without the person's consent is a reach of data privacy.

It violates the privacy of Information right of the Girl, except for Security or other specified reasons no Organisations or person is given the right to divulge another person's right to a third party, ALL THESE VIOLATIONS ARE PUNISHABLE UNDER THE LAWS OF THE LAND.

4 0
3 years ago
Write an algorithm that will read a number (N). Calculate and display all numbers divisible by 5 from 1 to N.
DiKsa [7]

Answer:

Write an algorithm that will read a number (N). Calculate and display all numbers divisible by 5 from 1 to N. Answer (Algorithm) Start Declare integer variables ...

Explanation:

3 0
3 years ago
Rain,snow,wind,clouds are part of
Verizon [17]

Answer:

The Troposphere

Explanation:

This is the lowest part of the atmosphere - the part we live in. It contains most of our weather - clouds, rain, snow. In this part of the atmosphere the temperature gets colder as the distance above the earth increases

5 0
2 years ago
Write a full class definition for a class named Averager, and containing the following members: An data member named sum of type
RUDIKE [14]

Answer:

//program in java.

import java.io.*;

class Averager {

   public static int sum;

   public static int count;    

   //constructor to initialize values

   Averager(){

       sum = 0;

       count = 0;

   }

   //Method to return Sum

   public static int getSum(){

       return sum;

   }

   //Method to add the value passed in parameter

   public static void add(int num){

       sum=sum+num;

       count=count+1;

   }

   //Method to return Count

   public static int getCount(){

       return count;

   }

   //Method to return Average

   public static double getAverage(){

//type casting is used

       return (double) sum / (double) count;

   }      

   //User Driven Input method to run the program

public static void main (String[] args)throws IOException {

    //Using BufferedReader class for reading input

    InputStreamReader x = new InputStreamReader(System.in);

    BufferedReader inp = new BufferedReader(x);

    int n;

    do{

 System.out.println("Enter your choice");

 System.out.println("1.getSum()");

 System.out.println("2.add()");

 System.out.println("3.getCount()");

 System.out.println("4.getAverage()");

 System.out.println("5.Exit");

 n=Integer.parseInt(inp.readLine());

 switch(n)

 {

     case 1 : int s = getSum();

              System.out.println("The Sum is " + s);

              break;

     case 2 : System.out.println("Enter the number to add");

              int num;

              num=Integer.parseInt(inp.readLine());

              add(num);

              break;

     case 3 : int c = getCount();

              System.out.println("The Count is " + c);

              break;

     case 4 : double avg = getAverage();

              System.out.println("The Average is " + avg);

              break;

     default : break;

 };

    }while(n!=5);

    System.out.println("Exiting");

}

}

Explanation :

Average() constructor is used for initialization. Method getSum() will return the value of sum. Method getCount() will return the count and method getAverage() will return the average. The average will be of double type. User driver input is designed to call the methods as and when required.

Input:

Enter your choice

1.getSum()

2.add()

3.getCount()

4.getAverage()

5.Exit

1

Output:

The Sum is 0

7 0
3 years ago
The type of analysis that is most dependent upon the use of a computer is ____ analysis
kap26 [50]
The answer is simulation
5 0
3 years ago
Other questions:
  • A unique feature of which browser is an opening screen that features a different image each day with embedded links?
    9·2 answers
  • Historically, development of a new technology often:
    13·2 answers
  • What type of things can be marketed
    11·1 answer
  • Explain gui in detail​
    5·1 answer
  • What would happen without satellites???
    12·2 answers
  • LAB: Winning team (classes)
    14·1 answer
  • Pls can anyone be so kind and answer this question.....i need the answer urgently
    8·1 answer
  • Which memory can be removed from motherboard? RAM OR ROM?​
    11·1 answer
  • What term is the ability to restore service quickly and without lost data if a disaster makes your components unavailable or it
    15·1 answer
  • _____ regulate current/voltage flow, similar function as _____,but are smaller, cheaper, and more reliable.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!