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
mixer [17]
3 years ago
5

g write a recursive function that prints out all the even numbers between x and y inclusive if x is odd then the print out will

start at x 1
Computers and Technology
1 answer:
Reil [10]3 years ago
3 0

Answer:

The function written in python is as follows:

def EvenNumbers(x, y):

    if (y < x):

         return

    if (y % 2 == 0):

         EvenNumbers(x, y - 2)

    else:

         EvenNumbers(x, y - 1)

    if (y % 2 == 0):

         print(y)

Explanation:

x represents the lower limit while y represents the upper limit.

So, the recursion will be repeated as long as x <= y

This defines the function

def EvenNumbers(x, y):

This checks if y < x. If yes, the recursion stops execution and return to the main

<em>     if (y < x): </em>

<em>          return </em>

The following if and else condition checks determines the appropriate range of the recursion.

<em>     if (y % 2 == 0): </em>

<em>          EvenNumbers(x, y - 2) </em>

<em>     else: </em>

<em>          EvenNumbers(x, y - 1) </em>

The above takes care of printing starting at x + 1 if x is odd

This checks and prints the even numbers in the range

<em>     if (y % 2 == 0): </em>

<em>          print(y)</em>

<em />

To call the function from main, make use of

EvenNumbers(x, y)

Where x and y are integers

e.g EvenNumbers(2,10), EvenNumbers(1,17), EvenNumbers(3,21)

<em>See attachment</em>

You might be interested in
Which class members should be declared as public?
yawa3891 [41]

Answer:

B. Methods and occasionally final attributes

Explanation:

In Computer programming, class members can be defined as the members of a class that typically represents or indicates the behavior and data contained in a class.

Basically, the members of a class are declared in a class, as well as all classes in its inheritance hierarchy except for destructors and constructors.

In a class, member variables are mainly known as its attributes while its member function are seldomly referred to as its methods or behaviors.

One of the main benefits and importance of using classes is that classes helps to protect and safely guard their member variables and methods by controlling access from other objects.

Therefore, the class members which should be declared as public are methods and occasionally final attributes because a public access modifier can be accessed from anywhere such as within the current or external assembly, as there are no restrictions on its access.

6 0
3 years ago
The worst "review platform" (e.g. TripAdvisor, Zomato, Yelp) that can't be trusted?
BigorU [14]

I think it would be Zomato since its not popular and probably have bad and fake reviews.

4 0
3 years ago
How many functions can Excel perform?
Vlad [161]

Answer:

G

Explanation:

because

3 0
4 years ago
Does anyone know any nitro type hack??
alexgriva [62]

Answer:

yes nitro hack is where they time your hacking skills

5 0
4 years ago
Read 2 more answers
One of the many roles of the security compliance committee is to focus on controls that are widely used across a large populatio
asambeis [7]
ghffyhhuuhhhvccfghhnnnjki
3 0
2 years ago
Other questions:
  • What is print media?
    14·1 answer
  • What does the hard disk drive do?
    9·2 answers
  • What type of storage system is a hard drive on a computer?<br> Need HELP fast, please.
    9·2 answers
  • What data does Bittorrenting uses? Explain.
    5·1 answer
  • What is information systems​
    5·1 answer
  • In Windows, the log that stores events from a single application or component rather than events that might have system wide imp
    14·1 answer
  • In a stream channel what is deposited first?
    7·1 answer
  • This decision control structure enables the program to execute a statement or block of codes if and only if the Boolean expressi
    7·1 answer
  • The Beaufort Wind Scale is used to characterize the strength of winds. The scale uses integer values and goes from a force of 0,
    10·1 answer
  • What is a computer? ​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!