In: Computer Science
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!):
Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers)
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
#function called
def evenorodd():
#Even Numbers
print("Even numbers:", end = " ")
#for loop will iterate 1 to 2020
#2021 excluded
for i in range(1,2021):
#if i divided by 2 and remainder = 0
if i%2 == 0:
#printing the number
print(i,end = " ")
print("\n\n")
#Odd Numbers
print("Odd numbers:", end = " ")
#for loop will iterate 1 to 2020
#2021 excluded
for i in range(1,2021):
#if i divided by 2 and remainder = 1
if i%2 == 1:
#printing the number
print(i,end = " ")
#calling function
evenorodd()
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!