Question

In: Computer Science

The following is an incomplete function definition of the void function named SomeFun: ________________________________ if (n1...

The following is an incomplete function definition of the void function named SomeFun:

 ________________________________
   if (n1 > 0):
      index = n2
      while index < n3:
         print(index, end=" ")
         index += n1
   else:
      print("step should be positive.")


The function SomeFun takes 3 numbers as parameters and tries to print numbers
between the first and the second parameters with the increment of the third parameter.  
For example function call SomeFun(1, 10, 2) generates
1 3 5 7 9
The function call SomeFun(10, 1, -2) generates
step should be positive.

Complete the function definition by writing the function header.

Solutions

Expert Solution

The missing function header should be:

def SomeFun(n2, n3, n1):

Explanation:

This is because , first of all, def keyword is used to define a function and inside the brackets present after that, there comes the parameters passed to the function.

In this case, the parameters passed are n1, n2 and n3.

Now, the order of the parameters should be decided by looking at the definition of the function given above.

It is clearly visible that if n1 is less than or equal to 0, it prints that Step should be positive. So the step is n1 variable.

And while Calling the function, step is passed as the last parameter, so n1 should be the last parameter of the function.

Now n2 is the starting point of the range and n3 is the ending point as index < n3 is used in the while loop.

So, while Calling the function, starting of the range is passed as the first parameter, that is n2 and second parameter should be n3.

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!


Related Solutions

Make a function definition in C for the following: void insert (double *b, int c, double...
Make a function definition in C for the following: void insert (double *b, int c, double s, int pos); //Insert value s at position pos in array. //needs: // c > 0, pos >= 0, and pos <= c-1. Elements b[0]...b[c-1] exist. //this will do: //Elements from indexes pos up to c-2 have been moved up to indexes pos+1 up to c-1. The value s has been copied into b[pos]. //Note: the data that was in b[c-1] when the function...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
c++ Write the definition of a function named ‘isLower’ that takes as input a char value...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value and returns true if the character is lowercase; otherwise, it returns false.•Print the message “The character xis lowercase” when returned value above is true, and vice versa.
C++ PLEASE Write a new program called Lab15A Write a void function named fillArray that receives...
C++ PLEASE Write a new program called Lab15A Write a void function named fillArray that receives an array of 10 integers as a parameter and fills the array by reading the values from a text file (Lab15A.txt). It should also print the values of the array all on the same line, separated by spaces. Write an int function named findLast that receives an array of 10 integers as a parameter and returns the last negative number in the array. Write...
Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that...
Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that generates and stores a specified number of random numbers each of whose values are between 0 and 1000 in an array
Study the following class definition: class Car { public: Car(double speed); void start(); void accelerate(double speed);...
Study the following class definition: class Car { public: Car(double speed); void start(); void accelerate(double speed); void stop(); double get_speed() const; private: double speed; }; Which of the following options would make logical sense in the definition of the void accelerate(double speed)function? Group of answer choices this->speed = this->speed; this->speed = speed; this.speed = speed; speed1 = this->speed; Flag this Question Question 131 pts The Point class has a public function called display_point(). What is the correct way of calling...
Multiple choice Questions: 1) A simple (but incomplete) definition of a/an______ is that it is a...
Multiple choice Questions: 1) A simple (but incomplete) definition of a/an______ is that it is a mathematical entity that has a specific magnitude and direction. A. director B. aviator C. bisector D. scalar E. vector 2) It is a physical quantity expressible by a single real number whose value is independent of the coordinate system (of ordinary physical space). A ________can have a direction in an abstract space. For example, temperature on the Celsius scale: it can have positive or...
Determine if each of the following recursive definition is a valid recursive definition of a function...
Determine if each of the following recursive definition is a valid recursive definition of a function f from a set of non-negative integers. If f is well defined, find a formula for f(n) where n is non-negative and prove that your formula is valid. f(0) = 1, f(n) = -f(n-1) + 1 for n ≥ 1 f(0) = 0, f(1) = 1, f(n) = 2f(n-1) +1 for n ≥ 1 f(0) =0, f(n) = 2f(n-1) + 2 for n ≥...
(The Colorable interface) Design an interface named Colorable with a void method named howToColor(). Every class...
(The Colorable interface) Design an interface named Colorable with a void method named howToColor(). Every class of a colorable object must implement the Colorable interface. Design a class named Square that extends GeometricObject and implements Colorable. Design another class named Triangle that extends GeometricObject and implements Colorable. Implement howToColor in Square to display the message Color all four sides. Implement howToColor in Triangle to display the message Color all three sides. Draw a UML diagram that involves Colorable, Square, Triangle,...
What is time Complexity each of the following function? 1- void function(int n) {             for (int...
What is time Complexity each of the following function? 1- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n/2; j++)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 2- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n; j = 2 * j)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 3- void function(int n) {             for (int i=1; i<=n; i++)                           for (int j=1;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT