World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Can any one help me in this 5-55 thing Que - Using for loop and range() 4)Print 5- 55 in steps of 10
Certainly! Here is one way to solve this problem using a for loop and the range()
function:
for i in range(5, 56, 10): print(i)
This will print the numbers 5, 15, 25, 35, 45, and 55, each on a separate line.
Here's how this works:
range(5, 56, 10)
generates a sequence of numbers starting at 5, and ending before 56 (that is, it will generate the numbers 5, 15, 25, 35, 45). The 10
specifies the step size, so it will skip over numbers by increments of 10.for
loop will iterate over this sequence of numbers, and on each iteration, it will assign the value of the current number to the variable i
, and then execute the indented code block. In this case, the code block is just a single line that prints i
.I hope this helps! Let me know if you have any questions.