All Courses

Create a Function which will print all even and odd numbers over a specified range

By Manerushi149@gmail.com, 3 months ago
  • Bookmark
0

kindly assist me with the 10th question from Functions Que : Create a Function which will print all even and odd numbers over a specified range 

Functions
Python
Even and odd
Range
2 Answers
0
Hitendradixit18@gmail.com

hint- you need to check about range function with stepping value that we have discussed in the session

0
Goutamp777

Certainly! Here is an example of how you could create a function to print all even and odd numbers within a specified range:

def print_even_odd(start, end):
  for num in range(start, end+1):
    if num % 2 == 0:
      print(num, "is even")
    else:
      print(num, "is odd")


# Example usage
print_even_odd(1, 10)

This function takes in two arguments: start and end, which specify the range of numbers to consider. The function then uses a loop to iterate over the numbers in that range and uses the modulo operator (%) to determine whether each number is even or odd. If the number is even, it prints "is even"; if the number is odd, it prints "is odd".

I hope this helps! Let me know if you have any questions.

Your Answer

Webinars

Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More