Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Найти сумму и произведение цифр трехзначного числа, которое вводит пользователь.

inp_str = input('Please provide 3 digit integer value : ').lstrip().rstrip()
if len(inp_str) != 3:
print (f'It is not 3 digit integer value')
else:
d1 = int(inp_str[0])
d2 = int(inp_str[1])
d3 = int(inp_str[2])
print(f'Summa is : {d1 + d2 + d3}')
print(f'Product is : {d1 * d2 * d3}')
13 changes: 13 additions & 0 deletions task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Выполнить логические побитовые операции "И", "ИЛИ" и др. над числами 5 и 6.
# Выполнить над числом 5 побитовый сдвиг вправо и влево на два знака.

a = 5 # '101'
b = 6 # '110'

print (f'Binary AND is {a & b}') # '100'
print (f'Binary OR is {a | b}') # '111'
print (f'Binary XOR is {a ^ b}') # '011'

print (f'Binary shift 2 bits right is {a >> 2}') # '1'
print (f'Binary shift 2 bits left is {a << 2}') # '10100'

15 changes: 15 additions & 0 deletions task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# По введенным пользователем координатам двух точек вывести уравнение прямой вида
# y = kx + b, проходящей через эти точки.

print('Plese provide coordinates for a(x1;y1):')
x1 = float(input('\tx1 = '))
y1 = float(input('\ty1 = '))

print('Plese provide coordinates for b(x2;y2):')
x2 = float(input('\tx2 = '))
y2 = float(input('\ty2 = '))

k = (y1 - y2) / (x1 - x2)
b = y2 - k*x2
print(f'Formula of the line through points: a({x1};{y1}) and b({x2};{y2})')
print(' y = %.2f*x + %.2f' % (k, b))
59 changes: 59 additions & 0 deletions task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Написать программу, которая генерирует в указанных пользователем границах
# -случайное целое число,
# -случайное вещественное число,
# -случайный символ.
# Для каждого из трех случаев пользователь задает свои границы диапазона.
# Например, если надо получить случайный символ от 'a' до 'f', то вводятся эти символы.
# Программа должна вывести на экран любой символ алфавита от 'a' до 'f' включительно.

# случайное целое число
from random import randint
inp_str = input('Please provide 2 integer values separated by space: ').lstrip().rstrip()
val1, val2 = inp_str.split(' ')
val1 = int(val1)
val2 = int(val2)
if val1 > val2:
val1, val2 = val2, val1
print(f'Random integer is: {randint(val1, val2)}')

# случайное вещественное число
from random import uniform
inp_str = input('Please provide 2 decimal values separated by space: ').lstrip().rstrip()
val1, val2 = inp_str.split(' ')
val1 = float(val1)
val2 = float(val2)
if val1 > val2:
val1, val2 = val2, val1
print(f'Random integer is: {uniform(val1, val2)}')

from random import randint
# случайный символ вариант 1
inp_str = input('Please provide 2 lowercase English alphabet letters separated by space: ').lstrip().rstrip()
val1, val2 = inp_str.split(' ')
code1 = ord(val1)
code2 = ord(val2)
if code1 > code2:
code1, code2 = code2, code1
if code1 >122 or code1 < 97:
print (f'Error. {val1} is not lowercase English alphabet letters')
elif code2 >122 or code2 < 97:
print (f'Error. {val2} is not lowercase English alphabet letters')
else:
print(f'Random symbol is: {chr(randint(code1, code2))}')

from random import randint
# случайный символ вариант 2
inp_str = input('Please provide 2 lowercase English alphabet letters separated by space: ').lstrip().rstrip()
val1, val2 = inp_str.split(' ')
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
indx1 = ascii_lowercase.find(val1)
indx2 = ascii_lowercase.find(val2)
if indx1 > indx2:
indx1, indx2 = indx2, indx1
if indx1 == -1:
print (f'Error. {val1} is not lowercase English alphabet letters')
elif indx2 == -1:
print (f'Error. {val2} is not lowercase English alphabet letters')
else:
print(f'Random symbol is: {ascii_lowercase[randint(indx1, indx2)]}')

36 changes: 36 additions & 0 deletions task5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Пользователь вводит две буквы.
# Определить, на каких местах алфавита они стоят, и сколько между ними находится букв.
# Вариант 1
inp_str = input('Please provide 2 lowercase English alphabet letters separated by space: ').lstrip().rstrip()
val1, val2 = inp_str.split(' ')
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
indx1 = ascii_lowercase.find(val1)
indx2 = ascii_lowercase.find(val2)
if indx1 > indx2:
indx1, indx2 = indx2, indx1
if indx1 == -1:
print (f'Error. {val1} is not lowercase English alphabet letters')
elif indx2 == -1:
print (f'Error. {val2} is not lowercase English alphabet letters')
else:
print(f'Symbol [ {val1} ] is on pos {indx1 + 1}')
print(f'Symbol [ {val2} ]is on pos {indx2 + 1}')
print(f'Distance between symbol {val1} and symbol {val2} is {indx2 - indx1}')

# Вариант 2
mincode = 97
maxcode = 122
inp_str = input('Please provide 2 lowercase English alphabet letters separated by space: ').lstrip().rstrip()
val1, val2 = inp_str.split(' ')
code1 = ord(val1)
code2 = ord(val2)
if code1 > code2:
code1, code2 = code2, code1
if code1 < mincode or code1 > maxcode:
print (f'Error. {val1} is not lowercase English alphabet letters')
elif code2 < mincode or code2 > maxcode:
print (f'Error. {val2} is not lowercase English alphabet letters')
else:
print(f'Symbol [ {val1} ] is on pos {code1 - mincode +1}')
print(f'Symbol [ {val2} ]is on pos {code2 - mincode +1}')
print(f'Distance between symbol {val1} and symbol {val2} is {code2 - code1}')
17 changes: 17 additions & 0 deletions task6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Пользователь вводит номер буквы в алфавите. Определить, какая это буква.
# способ 1
number = int(input('Please provide lowercase English alphabet letter number : ').lstrip().rstrip())
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
if number > 26 or number <= 0:
print(f'Provided number is not valid, please retype: ')
else:
print(f'Your letter is {ascii_lowercase[number - 1]}')


# способ 2
number = int(input('Please provide lowercase English alphabet letter number : ').lstrip().rstrip())
mincode = 97
if number > 26 or number <= 0:
print(f'Provided number is not valid, please retype: ')
else:
print(f'Your letter is {chr(mincode + number - 1)}')
19 changes: 19 additions & 0 deletions task7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# По длинам трех отрезков, введенных пользователем, определить возможность существования треугольника,
# составленного из этих отрезков. Если такой треугольник существует, то определить,
# является ли он разносторонним, равнобедренным или равносторонним.

print('Plese provide lengths sides of triangle:')
l1 = float(input('\tl1 = '))
l2 = float(input('\tl2 = '))
l3 = float(input('\tl3 = '))

if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l1 + l2 :
print (f'It is possible to create triangle from provided sides')
if l1 != l2 and l2 != l3 and l3 != l1 :
print(f'Here is an scalene triangle')
elif l1 == l2 and l2 == l3 and l3 == l1 :
print(f'Here is an equilateral triangle')
elif l1 == l2 or l1 == l3 or l2 == l3 :
print(f'Here is an isosceles triangle')
else:
print (f'It is impossible to create triangle from provided sides')
7 changes: 7 additions & 0 deletions task8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Определить, является ли год, который ввел пользователем, високосным или не високосным.

year = int(input('Please provide Year number as 4 digits value: ').rstrip().lstrip())
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print(f'{year} is leap year')
else:
print(f'{year} is not leap year')
16 changes: 16 additions & 0 deletions task9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Вводятся три разных числа.
# Найти, какое из них является средним (больше одного, но меньше другого).

print('Plese provide 3 different numbers:')
n1 = float(input('\tn1 = '))
n2 = float(input('\tn2 = '))
n3 = float(input('\tn3 = '))

if (n1 > n2 and n1 < n3) or (n1 < n2 and n1 > n3):
print(f'{n1} is between {n2} and {n3}')
elif (n2 > n3 and n2 < n1) or (n2 < n3 and n2 > n1):
print(f'{n2} is between {n1} and {n3}')
elif (n3 > n1 and n3 < n2) or (n3 < n1 and n3 > n2):
print(f'{n3} is between {n1} and {n2}')
else:
print(f'All 3 numbers must be different')