52,624 views
41 votes
41 votes
Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 5 as long as the value is less than or equal to the second integer. Ex: If the input is: "-15" 10 the output is: "-15" "-10" "-5" 0 5 10 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first.

User Florian Wolters
by
2.8k points

1 Answer

16 votes
16 votes

Answer:

The program in Python is as follows:

num1 = int(input())

num2 = int(input())

if num2 < num1:

print("Second integer can't be less than the first.")

else:

for i in range(num1,num2+1,5):

print(i,end=" ")

Step-by-step explanation:

This gets the first integer from the user

num1 = int(input())

This gets the second integer from the user

num2 = int(input())

If the second is less than the first, the following prompt is printed

if num2 < num1:

print("Second integer can't be less than the first.")

If otherwise, the number between the intervals is printed with an increment of 5

else:

for i in range(num1,num2+1,5):

print(i,end=" ")

User Slifty
by
2.9k points