Loop control and swapping values
Answers are for parents and teachers.
1
Print the numbers from 1 to 10 but use break when 7 is reached. Write the result.
1 2 3 4 5 6
2
Write a program that adds the typed numbers and stops when 0 is typed (8 for 3, 5, 0).
s = 0 ⏎ while True: ⏎ n = int(input()) ⏎ if n == 0: ⏎ break ⏎ s += n ⏎ print(s)
3
Print the numbers from 1 to 12 that are not multiples of 4, using continue.
for i in range(1, 13): ⏎ if i % 4 == 0: ⏎ continue ⏎ print(i, end=" ")
4
If x = 5 and y = 8, what are x and y after x, y = y - x, x + y?
x = 3, y = 13