Problem 1.1
Print Five
Write a python program to print numbers from 1 to 5.
Solution
print(1)
print(2)
print(3)
print(4)
print(5)
Discussion
This problem is given to make the participants explore the interface to solve problems and submit them.
The problem as such is very simple. You just need to print numbers 1 to 5, with mutiple print statements.
print(1)
print(2)
print(3)
print(4)
print(5)
If you know how to use a for
loop in Python, you can do that in a loop by providing the numbers 1, 2, 3, 4, and 5 as a list.
for n in [1, 2, 3, 4, 5]:
print(n)
Or you could use the range
function to create the sequence of numbers instead of creating the list manually.
for n in range(1, 6):
print(n)
The call range(n)
gives n
numbers from 0
to n-1
. If you want numbers from 1
to n
, we need to use range(1, n+1)
.