Loops with Ranges
Explore how to use Python's range function to generate numeric sequences within loops. Learn to create programs that count, print even and odd numbers, generate multiples, and solve practice problems with user input.
The range() function
The range() function is used to generate a sequence of values. For example, range(100) generates values to . If we provide two parameters to this function, like range(10,100), it generates values starting from to .
It also makes it easy to specify the increment or jump value. For example, range(10,100,2) generates even values starting from and less than . Note that 2 here is the stepping size.
Loop with range()
Let’s say we want to produce a program that counts from ...