You are on page 1of 5

Laboratory session – 1.

Introduction to Data Science. Python Language Basics.


Conditional Statement and Comparison Operators
Option 1.
1. Given a natural number. You need to determine whether the year with
this number is a leap year. If the year is a leap year, output YES,
otherwise output NO.

Hint: Recall that according to the Gregorian calendar, a year is a leap year if its number
is a multiple of 4, but not a multiple of 100, and also if it is a multiple of 400.

2. Thechocolate bar has the form of a rectangle divided into n×m slices.
The chocolate bar can be broken once in a straight line into two parts.
Determine whether it is possible to break off a piece of chocolate that
consists of exactly k slices in this way. The program receives three
numbers as input: n, m, k and should output YES or NO.

Option 2.
1. Three integers are given. Find the largest of them (the program should
output exactly one integer).
!!! Use exactly two comparison operators(>, <, >=, <=) to solve this problem. You cannot use
the max and min functions.
2. Letbe given a and b. Solve the equation ax+b=0 in integers. Print all
the solutions to this equation, if their number is finite, print the word
NO, if there are no solutions, print the word INF, if there are infinitely
many solutions.

Option 3.
1. Given three natural numbers a, b, c. Determine whether there is a
triangle with such sides. If the triangle exists, output the string YES,
otherwise output the string NO.

Hint: A triangle is three points that do not lie on the same straight line.

2. Given three sides of the triangle a, b, c. Determine the type of triangle


with the given sides. Print one of the four words: rectangular for a right
triangle, acute for an acute triangle, obtuse for an obtuse triangle, or
impossible if a triangle with such sides does not exist.
Option 4.
1. Three integers are given. Determine how many of them match. The
program should output one of the numbers: 3 (if all match), 2 (if two
match) or 0 (if all the numbers are different).
2. There are two boxes, the first one is A1×B1×C1, the second one is
A2×B2×C2. Determine whether one of these boxes can be placed inside
the other, provided that the boxes can only be rotated 90 degrees around
the edges.
The program should output one of the following lines:
Boxes are equal if the boxes are the same,
The first box is smaller than the second one, if the first box can be put in the second one,
The first box is larger than the second one, if the second box can be put in the first one,
Boxes are incompatible, in all other cases.
For Loop
Option 1.
1. Given two integers A and B (with A≤B). Print all the numbers from A
to B, inclusive.
2. From the given non-negative integers n and k, calculate the value of
n!
the number of combinations of n elements in k, that is, k ! ( n−k ) !

3. Find and output all two-digit numbers that are equal to twice the
product of their digits.
Option 2.
1. Given two integers A and B. Output all the numbers from A to B
inclusive, in ascending order if A < B, or in descending order otherwise.
2. For a given natural n≥2, calculate the sum 1×2+2×3+...+(n-1)×n.
Output the answer as a calculated expression and its values exactly as
shown in the example.

3. The square of a three-digit number ends with three digits equal to that
number. Find and output all such numbers.
Option 3.
1. Given a natural number n. Print all n-digit odd natural numbers in
descending order.
2. Based on the two natural numbers A and B (A≤B), print all the even
numbers on the segment from A to B. You cannot use the if statement in
this task.
3. Given a natural number n. Print in ascending order all three-digit
numbers whose sum of digits is equal to n.
Option 4.
1. For a given non-negative integer n, calculate the value of n!.
2. Several numbers are given. Calculate how many of them are zero, and
output this number.
3. Two four-digit numbers A and B are given. Print in ascending order
all four-digit numbers in the range from A to B, the entry of which
contains exactly three identical digits.

You might also like