147k views
2 votes
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger.

1 Answer

1 vote

Answer:

x = int(input("Enter an integer: "))

y = int(input("Enter another integer: "))

if x > y:

for number in range(y+1, x):

print(number, end=" ")

elif y > x:

for number in range(x+1, y):

print(number, end=" ")

else:

print("There are no integers between {} and {}".format(x, y))

Step-by-step explanation:

*The code is in Python.

Ask the user to enter the two integers, x and y

Since we want our program to run regardless of which entered value is larger, we need to compare the numbers to be able to create the loop that prints the numbers.

Check if x is greater than y. If it is, create a for loop that iterates from y+1 to x-1 and print the numbers

Otherwise, check if y is greater than x. If it is, create a for loop that iterates from x+1 to y-1 and print the numbers

If none of the previous part is executed, print that there are no integers between

User Naren Yellavula
by
4.9k points