Tutor Chetan
Python - Programming Language
Snakify.org - Problem Solution
Input, Print and Number
1) Minimum of two numbers
Statement: Given two integers, print the smaller value.
Model solution
- a = int(input())
- b = int(input())
- if a < b:
- print(a)
- else:
- print(b)
2) Sign function
Statement: For the given integer X print 1 if it's positive, -1 if it's negative, or 0 if it's equal to zero.
Try to use the cascade if-elif-else for it.
Model solution
- x = int(input())
- if x > 0:
- print(1)
- elif x == 0:
- print(0)
- else:
- print(-1)
3) Minimum of three numbers
Statement: Given three integers, print the smallest value.
Model solution
- a = int(input())
- b = int(input())
- c = int(input())
- if b >= a <= c:
- print(a)
- elif a >= b <= c:
- print(b)
- else:
- print(c)
- # num1 = int(input("Input: "))
- # num2 = int(input("Input: "))
- # num3 = int(input("Input: "))
- # if num1 < num2 and num1 < num3:
- # print(num1)
- # elif num2 <num1 and num2 < num3:
- # print(num2)
- # else:
- # print(num3)
4) Equal numbers
Statement: Given three integers, determine how many of them are equal to each other. The program must print one of these numbers: 3 (if all are the same), 2 (if two of them are equal to each other and the third is different) or 0 (if all numbers are different).
Model solution
- a = int(input())
- b = int(input())
- c = int(input())
- if a == b == c:
- print(3)
- elif a == b or b == c or a == c:
- print(2)
- else:
- print(0)
- #num1 = int(input("Input: "))
- # num2 = int(input("Input: "))
- # num3 = int(input("Input: "))
- # if num1 == num2 and num1 == num3:
- # print("3")
- # elif num1 != num2 and num1 != num3 and num2 != num3:
- # print("0")
- # else:
- # print("2")
5) Rook move
Statement: Chess rook moves horizontally or vertically. Given two different cells of the chessboard, determine whether a rook can go from the first cell to the second in one move.
The program receives the input of four numbers from 1 to 8, each specifying the column and row number, first two - for the first cell, and then the last two - for the second cell. The program should output YES if a rook can go from the first cell to the second in one move, or NO otherwise.
- r1 = int(input("Input: "))
- c1 = int(input("Input: "))
- r2 = int(input("Input: "))
- c2 = int(input("Input: "))
- if r1 == r2 or c1 == c2:
- print("YES")
- else:
- print("NO")
6) Chess Board - Same color
Statement: Given two cells of a chessboard. If they are painted in one color, print the word YES, and if in a different color - NO.
The program receives the input of four numbers from 1 to 8, each specifying the column and row number, first two - for the first cell, and then the last two - for the second cell.
Model solution
- x1 = int(input())
- y1 = int(input())
- x2 = int(input())
- y2 = int(input())
- if (x1 + y1 + x2 + y2) % 2 == 0:
- print('YES')
- else:
- print('NO')
7) Leap year
Statement: Given the year number. You need to check if this year is a leap year. If it is, print LEAP
, otherwise print COMMON
.
The rules in Gregorian calendar are as follows:
- a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100
- a year is always a leap year if its number is exactly divisible by 400
Warning. The words LEAP
and COMMON
should be printed all caps.
Model solution
- year = int(input())
- if (year % 4 == 0) and (year % 100 != 0) or (year % 400 == 0):
- print('LEAP')
- else:
- print('COMMON')
0 Comments