tripsman
tripsman

Reputation: 11

Why is the "B" code not printing the required range?

Hi I'm trying to make a function to print a range of numbers. the "A" code runs correctly but the "b" code only prints "50"

(A) correctly print 50, 60, 70,80,90, 100

for i in range (50,110,10):
    print(i)

(B) print 50 only

def rest(rmin,rmax,intervals):
    for i in range(rmin,rmax,intervals):
       return i
print(rest(50,110,10))

Upvotes: 1

Views: 50

Answers (1)

Noctis Skytower
Noctis Skytower

Reputation: 21991

Please see the following code for accomplishing what you are trying to do:

>>> for integer in range(50, 110, 10):
    print(integer)


50
60
70
80
90
100
>>> def rest(minimum, maximum, interval):
    for integer in range(minimum, maximum, interval):
        yield integer


>>> print(*rest(50, 110, 10), sep='\n')
50
60
70
80
90
100
>>> 

Upvotes: 1

Related Questions