Give a segment of python code that will print the numbers 1 to 7, each one on a new line

for x in range(1,8) : print(x) The range(1,8) function gives us an array of numbers from 1 to 7. The number on the right is the upper bound of the numbers which is why only 1 to 7 is returned.From here, a for loop is used, basically saying for each number inside the array, print this number.

JC

Related Python Mentoring answers

All answers ▸

What is the difference between a cycle "if" and "while"?


Write a program that takes a value x and then outputs x Fibonnaci numbers. E.g. if x=6 output would be 1 1 2 3 5 8


How would you get a piece of code to print the numbers 1 to 10


How do I use format python code?