Question: (Python 3.8)# Q9. Write a program to display all even numbers that falls between two numbers (exclusive both numbers) entered from the user. For this

(Python 3.8)# Q9. Write a program to display all even numbers that falls between two numbers (exclusive both numbers) entered from the user. 

For this problem, does it make a difference whether I use an if statement or a for statement first?

This was my solution to the problem:

num1 = int(input("Please enter your first number: ")) num2 = int(input("Please enter your second number: ")) for i in range(num2+1, num1): if num1 > num2 and i % 2 == 0: print(i) else: for i in range(num1+1, num2): if num2 > num1 and i % 2 == 0: print(i) 

And this was the website's solution:

num1 = int(input("Enter first number")) num2 = int(input("Enter second number")) if num1 > num2 : for i in range(num2+1 , num1): if i%2 == 0: print(i) else : for i in range(num1 + 1, num2): if i % 2 == 0: print(i)

Are both solutions the same or is there a difference in terms of replacing the order of the for and if statements?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!