While loop - Learn Python 3 - Snakify

Lesson 6.While loop



Problem «List of squares» (Easy)


Statement

For a given integer N, print all the squares of integer numbers where the square is less than or equal to N, in ascending order.



Problem «Least divisor» (Easy)


Statement

Given an integer not less than 2. Print its smallest integer divisor greater than 1.



Problem «The power of two» (Medium)


Statement

For a given integer N, find the greatest integer x where \( 2^x \) is less than or equal to N. Print the exponent value and the result of the expression \( 2^x \).

Don't use the operation **.





Problem «Morning jog» (Easy)


Statement

As a future athlete you just started your practice for an upcoming event. Given that on the first day you run x miles, and by the event you must be able to run y miles.

Calculate the number of days required for you to finally reach the required distance for the event, if you increases your distance each day by 10% from the previous day.

Print one integer representing the number of days to reach the required distance.



Problem «The length of the sequence» (Easy)


Statement

Given a sequence of non-negative integers, where each number is written in a separate line. Determine the length of the sequence, where the sequence ends when the integer is equal to 0. Print the length of the sequence (not counting the integer 0). The numbers following the number 0 should be omitted.



Problem «The sum of the sequence» (Medium)


Statement

Determine the sum of all elements in the sequence, ending with the number 0.



Problem «The average of the sequence» (Medium)


Statement

Determine the average of all elements of the sequence ending with the number 0.



Problem «The maximum of the sequence» (Medium)


Statement

A sequence consists of integer numbers and ends with the number 0. Determine the largest element of the sequence.



Problem «The index of the maximum of a sequence» (Hard)


Statement

A sequence consists of integer numbers and ends with the number 0. Determine the index of the largest element of the sequence. If the highest element is not unique, print the index of the first of them.



Problem «The number of even elements of the sequence» (Medium)


Statement

Determine the number of even elements in the sequence ending with the number 0.



Problem «The number of elements that are greater than the previous one» (Hard)


Statement

A sequence consists of integer numbers and ends with the number 0. Determine how many elements of this sequence are greater than their neighbours above.



Problem «The second maximum» (Hard)


Statement

The sequence consists of distinct positive integer numbers and ends with the number 0. Determine the value of the second largest element in this sequence. It is guaranteed that the sequence has at least two elements.



Problem «The number of elements equal to the maximum» (Hard)


Statement

A sequence consists of integer numbers and ends with the number 0. Determine how many elements of this sequence are equal to its largest element.



Problem «Fibonacci numbers» (Hard)


Statement

The Fibonacci sequence is defined as follows: $$ \phi_0 = 0, \ \phi_1 = 1, \ \phi_n = \phi_{n-1} + \phi_{n-2} . $$ Given a non-negative integer \( n \), print the \( n \)th Fibonacci number \( \phi_n \).

This problem can also be solved with a for loop.





Problem «The index of a Fibonacci number» (Hard)


Statement

The Fibonacci sequence is defined as follows: $$ \phi_0 = 0, \ \phi_1 = 1, \ \phi_n = \phi_{n-1} + \phi_{n-2} . $$ Given an integer \( a \), determine its index among the Fibonacci numbers, that is, print the number \( n \) such that \( \phi_n = a \). If \( a \) is not a Fibonacci number, print -1.



Problem «The maximum number of consecutive equal elements» (Hard)


Statement

Given a sequence of integer numbers ending with the number 0. Determine the length of the widest fragment where all the elements are equal to each other.