Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started