Branching practice and the for loop
Answers are for parents and teachers.
1
Write the numbers given by range(0, 30, 6).
0, 6, 12, 18, 24
2
Write a loop that prints the odd numbers from 1 to 20 on one line.
for i in range(1, 21, 2): ⏎ print(i, end=" ")
3
n is typed. Write a program that prints the sum of the numbers from 1 to n (5050 for n = 100).
n = int(input()) ⏎ s = 0 ⏎ for i in range(1, n + 1): ⏎ s += i ⏎ print(s)
4
Print a 3-row triangle of stars (1, 2, 3 stars) using a for loop.
for i in range(1, 4): ⏎ print("*" * i)