Write the definition of a function words_typed, that receives two parameters. The first is a person's typing speed in words per minute (an integer greater than or equal to zero). The second is a time interval in seconds (an integer greater than zero). The function returns the number of words (an integer) that a person with that typing speed would type in that time interval.

Respuesta :

Answer:

   //Method definition of words_typed

   //The return type is int

   //Takes two int parameters: typingSpeed and timeInterval

   public static int words_typed(int typingSpeed, int timeInterval) {

       //Get the number of words typed by  

       //finding the product of the typing speed and the time interval

       //and then dividing the result by 60 (since the typing speed is in "words

       // per minute"  and the time interval is in "seconds")

       int numberOfWords = typingSpeed * timeInterval / 60;

       

       //return the number of words

       return numberOfWords;

       

   }        //end of method declaration

Explanation:

The code above has been written in Java and it contains comments explaining each of the lines of the code. Please go through the comments.

Answer:

I am writing the program in Python.

def words_typed(typing_speed,time_interval):

   typing_speed>=0

   time_interval>0

   no_of_words=int(typing_speed*(time_interval/60))

   return no_of_words

   

output=words_typed(20,30)

print(output)

Explanation:

I will explain the code line by line.

First the statement def words_typed(typing_speed,time_interval) is the definition of a function named words_typed which has two parameters typing_speed and time_interval.

typing_speed variable of integer type in words per minute.

time_interval variable of int type in seconds

The statements typing_speed>=0 and time_interval>0 means that value of typing_speed is greater than or equal to zero and value of time_interval is greater than zero as specified in the question.

The function words_typed is used to return the number of words that a  person with typing speed would type in that time interval. In order to compute the words_typed, the following formula is used:

   no_of_words=int(typing_speed*(time_interval/60))

The value of typing_speed is multiplied by value of time_interval in order to computer number of words and the result of the multiplication is stored in no_of_words. Here the time_interval is divided by 60 because the value of time_interval is in seconds while the value of typing_speed is in minutes. So to convert seconds into minutes the value of time_interval is divided by 60 because 1 minute = 60 seconds.

return no_of_words statement returns the number of words.

output=words_typed(20,30) statement calls the words_typed function and passed two values i.e 20 for typing_speed and 30 for time_interval.

print(output) statement displays the number of words a person with typing speed would type in that time interval, on the output screen.

Ver imagen mahamnasir
ACCESS MORE
EDU ACCESS