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
Sliva [168]
3 years ago
8

Write a function getPigLatin(pigStr) that accepts pigStr as a parameter (a sentence as input) and converts each word to "Pig Lat

in." and returns the entire string in Pig Latin. In one version, to convert a word to Pig Latin, you remove the first letter and place that letter at the end of the word. Then, you append the string "ay" to the word. Here is an example:
English: I SLEPT MOST OF THE NIGHT


Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
Computers and Technology
1 answer:
Vladimir79 [104]3 years ago
8 0

Answer:

userInput = str(input("Enter your sentence here.\n")).upper()

def getPigLatin(userInput):

   splitInput = userInput.split(" ")

   newList = []

   for word in splitInput:

       firstLetter = word[0]

       if len(word) == 1:

           word += 'AY'

           newList.append(word)

       else:

           word = word.strip(word[0])

           word += firstLetter

           word += 'AY'

           newList.append(word)

   print(*newList, sep= " ")

getPigLatin(userInput)

Explanation:

This solution is done in Python

First the user is prompt to enter a statement, the statement converted to string and also capitalize using str and upper() built-in function. The user input is assigned to userInput variable.

The getPigLatin function is defined and it accept a string as parameter. Inside the getPigLatin function, the userInput is splitted and assigned to splitInput variable.

An empty list is also initialized and assigned to newList. Next, we loop through the splitInput. During the loop; we first check if the length of an element is one, then we just add 'AY' to the element and add the element to the newList. Else, if the element length is more than one; we strip the first letter from the word and also re-assign it to word, then the stripped first letter is added to the end of the word. Next, 'AY' is added to the word and the element is add to the newList.

The last line of the getPigLatin function display the entire element of the list using a space seperator.

The last line of the entire solution call the function passing in the userInput as argument.

You might be interested in
Assume that you have an array of integers named arr. The following program segment is intended to sum arr [0]through arr[n−1], w
Paladinen [302]

Answer:

There is only one modification in the above loop i.e. while loop should be like this--

while (i != n)

     {

         sum+=arr[i];   // Line 1, In question segment it is line 2.

          i++;                // Line 2,  In question segment it is line 1.

     }

Output:

Now if the array input is 1,2,3,4,5 then the output is 15.

Explanation:

In the above question, all the line of the segment is right except the body of the loop because--

  • The First line of the loop is increment statement which increments the value of "i" variable from 1 and the value of "i" variable will be 1 in the first iteration of the loop
  • The second line starts to add the value from 1'st index position of the array. Hence the segment gives the wrong answer. It adds the arr[1] to arr[n-1].
  • So I interchanged both lines of the while loop as shown in the answer part. I make the line 1 (In question segment) as line 2(In answer part) and line 2 (In question segment) as line 1 (In answer part).

Now It gives the correct output because it can add arr[0] to arr[n-1].

7 0
3 years ago
Write a class named Averager containing: An instance variable named sum of type integer, initialized to 0. An instance variable
vladimir1956 [14]

Answer:

The answer to this question can be given as:

Class definition:  

public class Averager  //define class Average.

{

private int sum = 0;

 //define variable sum.

private int count = 0;

 //define variable count.  

public int getSum() //define function getSum().

{

return sum;  //return value.

}

public void add(int x)

//define function add().

{

sum = sum + x;   //calculate sum

count=count+1; //increase value of count.

}

public int add(int x)

 //define function add().

{

return count;  //return value.

}

public double getAverage()  //define function getAverage().

{

return (double)sum/count;  //return value

}

}

Explanation:

The above class definition can be described as:

  • In the above class definition first we define a class that is " Averager". In this class we define two integer variable  that is "sum and count"  and assign a value that is 0. Then we define a functions :
  • First we define getSum() function in this function we does not pass any value and the return type of this function is int that will return an integer value.
  • Then we define add() function we use this function two times but both functions have different from each other.  
  • In first time implementation, we define this function and the return type of this function is void which means it does not return any value. In this function, we calculate the sum value and increase the value of the count variable by 1.  
  • In second time implementation, we define this function and the return type of this function is int which means it will return a value. In this function, we will return the count variable value.
  • At the last, we define a getAverage() that calculates the average of the added values in the sum variable and returns its value.
3 0
3 years ago
Which of these is outside the scope of an art director's responsibility?
Morgarella [4.7K]

Answer: telling the animators that an entire scene must be reworked

Explanation:

4 0
2 years ago
Read 2 more answers
Given the availability of an ifstream object named input, write the other statements necessary to read an integer into a variabl
tatiyna

Answer:

input.open("rawdata");

input>>datum;

input.close();

Explanation:

ifstream objects maintain a filebuf object as their internal stream buffer, and perform operations like input/output on the available associated files.

In above statements.

                            input.open("rawdata");

  • The associated file named rawdata is opened.

                            input>>datum;

  • The integer from the file is read into already declared variable datum.

                             input.close();

  • Input stream is closed.
4 0
2 years ago
Where do today's computers store almost all motherboard configuration data?
sergij07 [2.7K]
In the mother board of the back door next to the restroom 5 steps left
3 0
3 years ago
Other questions:
  • Technological _____ is the term used to describe the merging of several technologies into a single device.
    13·1 answer
  • When planning your educational and career path, it makes sense to consider where you want to work and what type of work you want
    14·1 answer
  • Technology is often discovered by accident
    5·1 answer
  • Which HTML tag is used to add a paragraph to a web page?
    15·1 answer
  • .What particular skills does a team leader need in addition to the other skills needed by any team member. (choose all that appl
    6·1 answer
  • Drag the tiles to the correct boxes to complete the pairs.
    13·1 answer
  • State five differences between Dos and Windows.​
    14·1 answer
  • Why would over-50 executives have a harder time buying into the idea of social media?​
    15·1 answer
  • What would be an ideal scenario for using edge computing solutions?
    6·1 answer
  • 9
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!