last lab
This commit is contained in:
24
labPython/lab4/MinMax27.py
Executable file
24
labPython/lab4/MinMax27.py
Executable file
@@ -0,0 +1,24 @@
|
||||
import random
|
||||
|
||||
nBit = int(input("Введите количество элементов N: "))
|
||||
bitArray = [random.randint(0, 1) for _ in range(nBit)]
|
||||
print(bitArray)
|
||||
countLen = 0
|
||||
countIndex = 0
|
||||
bitMax = 0
|
||||
bitMaxIndex = 0
|
||||
for i in range(len(bitArray)):
|
||||
if i < len(bitArray)-1:
|
||||
if bitArray[i] == bitArray[(i+1)]:
|
||||
countLen +=1
|
||||
if countLen > bitMax:
|
||||
bitMax = countLen
|
||||
bitMaxIndex = (i+2) - bitMax
|
||||
# countLen = 0
|
||||
|
||||
else:
|
||||
countLen = 0
|
||||
bitMax += 1
|
||||
|
||||
|
||||
print(bitMax, bitMaxIndex)
|
||||
44
labPython/lab4/Modul2.py
Executable file
44
labPython/lab4/Modul2.py
Executable file
@@ -0,0 +1,44 @@
|
||||
from random import randint
|
||||
def Gen():
|
||||
cartRandAndPorc = (randint(100, 1000), randint(1, 100))
|
||||
return cartRandAndPorc
|
||||
|
||||
def Question(procent):
|
||||
try:
|
||||
return int(input(f"{procent[1]} процен(т\ов) от числа {procent[0]}: "))
|
||||
except:
|
||||
pass
|
||||
def Proverka(answer, answerTrue):
|
||||
answerTrue = int((answerTrue[0]/100)*answerTrue[1])
|
||||
if answer == answerTrue:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def Ball(trulest, qCount)->int:
|
||||
point = 100//qCount
|
||||
if trulest == 1:
|
||||
return point
|
||||
else:
|
||||
return 0
|
||||
|
||||
def Mark(points):
|
||||
if points <= 40:
|
||||
return 2
|
||||
elif points <= 60:
|
||||
return 3
|
||||
elif points <= 80:
|
||||
return 4
|
||||
elif points > 80:
|
||||
return 5
|
||||
|
||||
points = 0
|
||||
qCount = int(input("Колличество вопросов: "))
|
||||
for i in range(1, qCount+1):
|
||||
|
||||
print("Вопрос ", i)
|
||||
gen = Gen()
|
||||
answer = Question(gen)
|
||||
points += Ball(Proverka(answer, gen), qCount)
|
||||
|
||||
print(f"Ваша оценка {Mark(points)}, общее число баллов: {points}")
|
||||
6
labPython/lab4/Reccur17.py
Executable file
6
labPython/lab4/Reccur17.py
Executable file
@@ -0,0 +1,6 @@
|
||||
def n_chlen(num_end):
|
||||
if num_end <= 1:
|
||||
return 2
|
||||
else:
|
||||
return (num_end+1)/num_end + n_chlen(num_end-1)
|
||||
print(n_chlen(2))
|
||||
6
labPython/lab4/Reccur2.py
Executable file
6
labPython/lab4/Reccur2.py
Executable file
@@ -0,0 +1,6 @@
|
||||
def maxNum(num_end:int) -> int:
|
||||
if num_end < 1:
|
||||
return 0
|
||||
else:
|
||||
return num_end%10 + maxNum(num_end//10)
|
||||
print(maxNum(0))
|
||||
Reference in New Issue
Block a user