Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Tema 3(Loops)

While:

1. Write a program that displays all natural numbers between 0 and 50.
2. Write a program that displays all even numbers between 0 and 100.
3. Write a program that displays the squares of all integers between 0 and
10.
4. Using the loop, write numbers from -20 to 20. Then write:

the first 6 numbers


 the last 6 numbers
 all even numbers
 all numbers except digit 5
 all numbers up to and including digit 7
 all numbers divisible by 3
 the sum of all numbers
 the sum of numbers greater than or equal to 4
 all numbers and their powers
 all numbers and their values for modulo 10

5. Write a program that displays numbers that are multiples of 5 and are
divisible by 7 within the range from 1500 to 2700.
6. Write a program that writes numbers from 0 to 6 and omits 3 and 6. Do it
in two versions: with and without the continue statement.

Do the same using for loop

For:

1. A 10-element array is given: a_list = [1, 3, 5, 2, 5, 6, 7, 4, 9, 7]. Write a program that


prints: ◦ all digits, ◦ the first 6 digits, ◦ ostatnich cyfr, ◦ all even digits, ◦ all digits on
odd indexes, ◦ all digits except digit 5, ◦ all digits up to and including digit 7, ◦ all digits
divisible by 3, ◦ the sum of all digits, ◦ the sum of digits greater than or equal to 4, ◦
the smallest and the largest digit.
2. Write a program that for the given number of words, e.g. a_list = ['cat', 'primer',
'window', 'computer'] will display subsequent items of the list together with
information about the length of these items.

3. Write a program that for the given list of words, e.g.


list_of_words = ["spam", "table", "spam", "brown", "air", "malware", "spam", "end"]
will display only the list items that have no "spam" value. In addition, if the list item
value is "malware", the program should terminate operation immediately. Use the
break statement. Search in the Internet for information on how the break statement
works.

4). Write a program that will display, one by one, all items together with their types
for a given list. For the following list:
a_list = [4, True, None]
the program should display the following result:
4 <class 'int'>
True <class 'bool'>
None <class 'NoneType'>

You might also like