1
The program must receive as input three values N, A, and B, and must print the multiples of N contained in the interval between A and B. I am doing it as follows, but it is going wrong:
N = int(raw_input())
A = int(raw_input())
B = int(raw_input())
x = range(A, B + 1, N)
try:
for i in range(A, B + 1, N):
if x == [1]:
print 'INEXISTENTE'
else:
print i
except:
if x == [1]:
print 'INEXISTENTE'
If there are no multiples of N in the given range, the program must print "NONEXISTENT". The code works for some values, but for others, for example 3, 5, 9 (N, A and B, respectively), it does not work. Another tried code:
N = int(raw_input())
A = int(raw_input())
B = int(raw_input())
x = range(A, B + 1, N)
for i in range(A, B + 1, N):
if i % N == 0:
print i
Also works for some values and for others not.
Updating:
N = int(raw_input())
A = int(raw_input())
B = int(raw_input())
x = range(A, B + 1)
for i in range(A, B + 1):
if i % N == 0:
print i
elif x == []:
print 'INEXISTENTE'
This last code doesn’t work either. If x has no values, that is, if there are no multiples in the range, the program should print 'NONEXISTENT', if the entries were, for example, 12, 1 and 10, where there are no multiples of 12 between 1 and 10.
Using its code, using as input: 3, 5, 9, it prints only the number 6, and also prints 'Nonexistent' three times. The expected output would be only 6 and 9, one on each line. 'Nonexistent' only applies to entries of type 12, 1, 10, where between 1 and 10 there are no multiples of 12.
– Guilherme Santana De Souza
I edited the question.
– Guilherme Santana De Souza