New changes
This commit is contained in:
parent
9b86dacd15
commit
4548a736d2
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1 @@
|
||||||
|
main.py
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (Wiederholung)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Wiederholung.iml" filepath="$PROJECT_DIR$/.idea/Wiederholung.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,148 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
# Посчитать сумму всех положительных чисел
|
||||||
|
def sum_positive(array):
|
||||||
|
q = 0
|
||||||
|
N = len(array)
|
||||||
|
for i in range(N):
|
||||||
|
if array[i] > 0:
|
||||||
|
q += array[i]
|
||||||
|
|
||||||
|
return q
|
||||||
|
|
||||||
|
|
||||||
|
# Посчитать сумму всех отрицательных чисел
|
||||||
|
def sum_negative(array):
|
||||||
|
q = 0
|
||||||
|
N = len(array)
|
||||||
|
for i in range(N):
|
||||||
|
if array[i] < 0:
|
||||||
|
q += array[i]
|
||||||
|
|
||||||
|
return q
|
||||||
|
|
||||||
|
|
||||||
|
# Посчитать сумму всех положительных чисел, если в массиве есть отрицательное число
|
||||||
|
# Если отрицательных чисел нет, вернуть 0
|
||||||
|
def sum_positive_if_negative(array):
|
||||||
|
q = 0
|
||||||
|
N = len(array)
|
||||||
|
for i in range(N):
|
||||||
|
if array[i] > 0:
|
||||||
|
q += array[i]
|
||||||
|
if array[i] < 0:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return q
|
||||||
|
|
||||||
|
|
||||||
|
# Посчитать сумму всех отрицательных чисел, если в массиве есть число 1
|
||||||
|
# Если числа 1 нет - посчитать сумму всех положительных чисел
|
||||||
|
def sum_negative_if_one(array):
|
||||||
|
q = int()
|
||||||
|
a = int()
|
||||||
|
for i in array:
|
||||||
|
if i == 1:
|
||||||
|
q += 1
|
||||||
|
if q > 0:
|
||||||
|
break
|
||||||
|
if q > 0:
|
||||||
|
for i in array:
|
||||||
|
if i < 0:
|
||||||
|
a += i
|
||||||
|
else:
|
||||||
|
for i in array:
|
||||||
|
if i > 0:
|
||||||
|
a += i
|
||||||
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Посчитать сумму чисел ДО первого отрицательного числа (не включая его)
|
||||||
|
def sum_before_negative(array):
|
||||||
|
q = -1
|
||||||
|
a = int()
|
||||||
|
for i in array:
|
||||||
|
q += 1
|
||||||
|
if i < 0:
|
||||||
|
break
|
||||||
|
if q >= 0:
|
||||||
|
for i in array[:q]:
|
||||||
|
a += i
|
||||||
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
# Посчитать сумму чисел ПОСЛЕ первого положительного числа (включая его)
|
||||||
|
def sum_after_positive(array):
|
||||||
|
q = -1
|
||||||
|
a = int()
|
||||||
|
for i in array:
|
||||||
|
q += 1
|
||||||
|
if i > 0:
|
||||||
|
break
|
||||||
|
if q >= 0:
|
||||||
|
for i in array[q:]:
|
||||||
|
a += i
|
||||||
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
def verifier(test_name, test_array, actual, expected):
|
||||||
|
print(test_name)
|
||||||
|
print(test_array)
|
||||||
|
if actual != expected:
|
||||||
|
print("=======> FAILED! <=======")
|
||||||
|
print(f"Got value <{actual}>")
|
||||||
|
print(f"Expected value is <{expected}>")
|
||||||
|
else:
|
||||||
|
print("PASSED")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
test_array10 = []
|
||||||
|
test_array100 = []
|
||||||
|
test_array1000 = []
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
test_array10.append(random.randint(0, 20) - 10)
|
||||||
|
test_array100.append(random.randint(0, 200) - 100)
|
||||||
|
test_array1000.append(random.randint(0, 2000) - 1000)
|
||||||
|
|
||||||
|
tests = [test_array10, test_array100, test_array1000, [], [0]]
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(len(tests)):
|
||||||
|
verifier(f"sum_positive TEST {i+1}", tests[i], sum_positive(tests[i]), sum([x for x in tests[i] if x > 0]))
|
||||||
|
|
||||||
|
for i in range(len(tests)):
|
||||||
|
verifier(f"sum_negative TEST {i+1}", tests[i], sum_negative(tests[i]), sum([x for x in tests[i] if x < 0]))
|
||||||
|
|
||||||
|
for i in range(len(tests)):
|
||||||
|
is_in = len([x for x in tests[i] if x < 0]) > 0
|
||||||
|
if is_in:
|
||||||
|
verifier(f"sum_positive_if_negative TEST {i+1}", tests[i], sum_positive_if_negative(tests[i]), sum([x for x in tests[i] if x > 0]))
|
||||||
|
else:
|
||||||
|
verifier(f"sum_positive_if_negative TEST {i+1}", tests[i], sum_positive_if_negative(tests[i]), 0)
|
||||||
|
|
||||||
|
for i in range(len(tests)):
|
||||||
|
is_in = len([x for x in tests[i] if x == 1]) > 0
|
||||||
|
if is_in:
|
||||||
|
verifier(f"sum_negative_if_one TEST {i+1}", tests[i], sum_negative_if_one(tests[i]), sum([x for x in tests[i] if x < 0]))
|
||||||
|
else:
|
||||||
|
verifier(f"sum_negative_if_one TEST {i+1}", tests[i], sum_negative_if_one(tests[i]), sum([x for x in tests[i] if x > 0]))
|
||||||
|
|
||||||
|
for i in range(len(tests)):
|
||||||
|
indices = [x for x in range(len(tests[i])) if tests[i][x] < 0]
|
||||||
|
if len(indices) > 0:
|
||||||
|
verifier(f"sum_before_negative TEST {i+1}", tests[i], sum_before_negative(tests[i]), sum(tests[i][:indices[0]]))
|
||||||
|
else:
|
||||||
|
verifier(f"sum_before_negative TEST {i+1}", tests[i], sum_before_negative(tests[i]), sum(tests[i]))
|
||||||
|
|
||||||
|
for i in range(len(tests)):
|
||||||
|
indices = [x for x in range(len(tests[i])) if tests[i][x] > 0]
|
||||||
|
if len(indices) > 0:
|
||||||
|
verifier(f"sum_after_positive TEST {i+1}", tests[i], sum_after_positive(tests[i]), sum(tests[i][indices[0]:]))
|
||||||
|
else:
|
||||||
|
verifier(f"sum_after_positive TEST {i+1}", tests[i], sum_after_positive(tests[i]), 0)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1 @@
|
||||||
|
main.py
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (pythonProject)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,45 @@
|
||||||
|
def mymin(array):
|
||||||
|
a = A[0]
|
||||||
|
for b in A:
|
||||||
|
if (a > b):
|
||||||
|
a = b
|
||||||
|
|
||||||
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
def mymax(array):
|
||||||
|
a = A[0]
|
||||||
|
for b in A:
|
||||||
|
if (a < b):
|
||||||
|
a = b
|
||||||
|
|
||||||
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
def mysum(array):
|
||||||
|
b = 0
|
||||||
|
for a in A:
|
||||||
|
b += a
|
||||||
|
|
||||||
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
A = [1, 4, 3, 7, 2, 9, 1, 10]
|
||||||
|
result = mymin(A)
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
A = [1, 4, 3, 7, 2, 9, 1, 10]
|
||||||
|
result = mymax(A)
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
A = [1, 4, 3, 7, 2, 9, 1, 10]
|
||||||
|
result = mysum(A)
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (CreateClass)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/CreateClass.iml" filepath="$PROJECT_DIR$/.idea/CreateClass.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,19 @@
|
||||||
|
class Rectangle():
|
||||||
|
def __init__(self, a, b):
|
||||||
|
self.a = a
|
||||||
|
self.b = b
|
||||||
|
|
||||||
|
|
||||||
|
def calculateArea(self):
|
||||||
|
area = int(self.a * self.b)
|
||||||
|
print('Die Fläche hat den Wert: ', area)
|
||||||
|
|
||||||
|
|
||||||
|
def calculateCircumference(self):
|
||||||
|
circumference = int(2*self.a + 2*self.b)
|
||||||
|
print('Der Umfang hat den Wert: ', circumference)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
class Triangle():
|
||||||
|
def __init__(self, a, b, c):
|
||||||
|
self.a = a
|
||||||
|
self.b = b
|
||||||
|
self.c = c
|
||||||
|
|
||||||
|
|
||||||
|
def calculateArea(self):
|
||||||
|
area = int((self.a + self.b + self.c)/2)
|
||||||
|
print('Die Fläche hat den Wert: ', area)
|
||||||
|
|
||||||
|
|
||||||
|
def calculateCircumference(self):
|
||||||
|
circumference = int(self.a + self.b + self.c)
|
||||||
|
print('Der Umfang hat den Wert: ', circumference)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
from ClassRectangle import Rectangle
|
||||||
|
from ClassTriangle import Triangle
|
||||||
|
|
||||||
|
triangle1 = Triangle(36, 12, 2)
|
||||||
|
triangle1.calculateArea()
|
||||||
|
|
||||||
|
triangle2 = Triangle(3, 9, 5)
|
||||||
|
triangle2.calculateCircumference()
|
||||||
|
|
||||||
|
triangle3 = Triangle(4, 12, 2)
|
||||||
|
triangle3.calculateArea()
|
||||||
|
|
||||||
|
rectangle1 = Rectangle(6, 6)
|
||||||
|
rectangle1.calculateArea()
|
||||||
|
|
||||||
|
rectangle2 = Rectangle(1, 12)
|
||||||
|
rectangle2.calculateCircumference()
|
||||||
|
|
||||||
|
rectangle3 = Rectangle(36, 21)
|
||||||
|
rectangle3.calculateArea()
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (pythonProject1)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject1.iml" filepath="$PROJECT_DIR$/.idea/pythonProject1.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,22 @@
|
||||||
|
def main_Sum(array):
|
||||||
|
sum = 0
|
||||||
|
for a in array:
|
||||||
|
sum += a
|
||||||
|
return sum
|
||||||
|
|
||||||
|
|
||||||
|
def main_Max(array):
|
||||||
|
max = array[0]
|
||||||
|
for b in array:
|
||||||
|
if b > max:
|
||||||
|
max = b
|
||||||
|
return max
|
||||||
|
|
||||||
|
|
||||||
|
def main_Min(array):
|
||||||
|
min = array[0]
|
||||||
|
for b in array:
|
||||||
|
if b <= min:
|
||||||
|
min = b
|
||||||
|
return min
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
def number_add_to_array(array):
|
||||||
|
number1 = input("Gebe eine ganze Zahl ein: ")
|
||||||
|
if number1.lstrip("-").isnumeric():
|
||||||
|
array.append(int(number1))
|
||||||
|
else:
|
||||||
|
print("Deine Eingabe ist keine ganze Zahl!")
|
||||||
|
|
||||||
|
|
||||||
|
def number_remove_from_array(array):
|
||||||
|
if len(array) > 0:
|
||||||
|
array.pop()
|
||||||
|
|
||||||
|
|
||||||
|
def my_array_menu(array):
|
||||||
|
print("Dein Array", array)
|
||||||
|
print("1. Einfügen")
|
||||||
|
print("2. Löschen")
|
||||||
|
print("3. Beenden")
|
||||||
|
|
||||||
|
|
||||||
|
def my_array_loop(array):
|
||||||
|
while True:
|
||||||
|
my_array_menu(array)
|
||||||
|
inp = input()
|
||||||
|
if inp.isnumeric():
|
||||||
|
op = int(inp)
|
||||||
|
if 1 <= op <= 3:
|
||||||
|
if op == 1:
|
||||||
|
number_add_to_array(array)
|
||||||
|
elif op == 2:
|
||||||
|
number_remove_from_array(array)
|
||||||
|
elif op == 3:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Wähle eien Nummer aus!")
|
||||||
|
else:
|
||||||
|
print("Gebe eine Zahl ein!")
|
|
@ -0,0 +1,51 @@
|
||||||
|
from Homework import main_Sum
|
||||||
|
from Homework import main_Max
|
||||||
|
from Homework import main_Min
|
||||||
|
from Homework1 import my_array_loop
|
||||||
|
from Homework1_2 import insertionsort
|
||||||
|
|
||||||
|
|
||||||
|
def main_menu():
|
||||||
|
print("Dein Array", array)
|
||||||
|
print("1. Сумма")
|
||||||
|
print("2. Максимум")
|
||||||
|
print("3. Минимум")
|
||||||
|
print("4. InsertionSort")
|
||||||
|
print("5. Array")
|
||||||
|
print("6. Выход")
|
||||||
|
|
||||||
|
|
||||||
|
array = []
|
||||||
|
|
||||||
|
while True:
|
||||||
|
main_menu()
|
||||||
|
inp = input()
|
||||||
|
if inp.isnumeric():
|
||||||
|
op = int(inp)
|
||||||
|
if 1 <= op <= 6:
|
||||||
|
if op == 1:
|
||||||
|
if len(array) > 0:
|
||||||
|
print(main_Sum(array))
|
||||||
|
else:
|
||||||
|
print("Dein Array ist leer!!!")
|
||||||
|
elif op == 2:
|
||||||
|
if len(array) > 0:
|
||||||
|
print(main_Max(array))
|
||||||
|
else:
|
||||||
|
print("Dein Array ist leer!!!")
|
||||||
|
elif op == 3:
|
||||||
|
if len(array) > 0:
|
||||||
|
print(main_Min(array))
|
||||||
|
else:
|
||||||
|
print("Dein Array ist leer!!!")
|
||||||
|
elif op == 4:
|
||||||
|
insertionsort(array)
|
||||||
|
elif op == 5:
|
||||||
|
my_array_loop(array)
|
||||||
|
elif op == 6:
|
||||||
|
print("Beenden")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Wähle eine Nummer!")
|
||||||
|
else:
|
||||||
|
print("Gebe eine Nummer ein!")
|
|
@ -0,0 +1,7 @@
|
||||||
|
def insertionsort(array):
|
||||||
|
for i in range(1, len(array)):
|
||||||
|
j = i
|
||||||
|
while array[j - 1] > array[j] and j > 0:
|
||||||
|
array[j - 1], array[j] = array[j], array[j - 1]
|
||||||
|
j -= 1
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
def count():
|
||||||
|
sentence = "Я пришел, я ушел, я нашел"
|
||||||
|
str1 = 'Я'
|
||||||
|
str2 = 'я'
|
||||||
|
if str1.lower() == str2.lower():
|
||||||
|
count1 = sentence.count(str1)
|
||||||
|
count2 = sentence.count(str2)
|
||||||
|
print("The count of 'Я' is", count1+count2)
|
||||||
|
|
||||||
|
sentence2 = sentence.count('пришел')
|
||||||
|
sentence3 = sentence.count('ушел')
|
||||||
|
sentence4 = sentence.count('нашел')
|
||||||
|
|
||||||
|
|
||||||
|
print("The count of 'пришел' is", sentence2)
|
||||||
|
print("The count of 'ушел' is", sentence3)
|
||||||
|
print("The count of 'нашел' is", sentence4)
|
||||||
|
|
||||||
|
count()
|
||||||
|
|
||||||
|
# from collections import defaultdict
|
||||||
|
|
||||||
|
# test_sentence = ["Я", "пришел", "я", "ушел", "я", "нашел"]
|
||||||
|
|
||||||
|
# print("The original sentence is : " + str(test_sentence))
|
||||||
|
|
||||||
|
# res = defaultdict(int)
|
||||||
|
|
||||||
|
# for count in test_sentence:
|
||||||
|
# res[count.lower()] += 1
|
||||||
|
|
||||||
|
# print("Strings Frequency : " +str(dict(res)))
|
|
@ -0,0 +1,17 @@
|
||||||
|
test_cases = [
|
||||||
|
("Sobaka", 1, 2),
|
||||||
|
("Koshka", 2, 3),
|
||||||
|
("Ezhik", 3, 4)
|
||||||
|
]
|
||||||
|
|
||||||
|
def print_zhivotny(mnogo_zhivotny):
|
||||||
|
for zhivotny in mnogo_zhivotny:
|
||||||
|
print("=" * 20)
|
||||||
|
test_name = zhivotny[0]
|
||||||
|
test_actual = zhivotny[1]
|
||||||
|
test_expected = zhivotny[2]
|
||||||
|
|
||||||
|
print(test_name, test_actual, test_expected)
|
||||||
|
print("=" * 20)
|
||||||
|
|
||||||
|
print_zhivotny(test_cases)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1 @@
|
||||||
|
main.py
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (Unit_Test)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Unit_Test.iml" filepath="$PROJECT_DIR$/.idea/Unit_Test.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,182 @@
|
||||||
|
# Сумма элементов массива
|
||||||
|
def sum_array(array):
|
||||||
|
# Что должна возвращать функция?
|
||||||
|
sum = 0
|
||||||
|
|
||||||
|
# Проводим вычисления
|
||||||
|
for a in array:
|
||||||
|
sum = sum + a
|
||||||
|
|
||||||
|
# Вернуть значение
|
||||||
|
return sum
|
||||||
|
|
||||||
|
|
||||||
|
# Из суммы элементов с четным индексом вычесть элементы с нечетным индексом (0 - четный)
|
||||||
|
def sum_diff_array(array):
|
||||||
|
# Что должна возвращать функция?
|
||||||
|
result = 0
|
||||||
|
|
||||||
|
# Проводим вычисления
|
||||||
|
for e in range(len(array)):
|
||||||
|
if e % 2 == 0:
|
||||||
|
result = result + array[e]
|
||||||
|
else:
|
||||||
|
result = result - array[e]
|
||||||
|
|
||||||
|
# Вернуть значение
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
# Максимальное число из массива помножить на минимальное число из массива
|
||||||
|
def max_mul_min_array(array):
|
||||||
|
sum = 0
|
||||||
|
|
||||||
|
|
||||||
|
# Развернуть строку (например "Abc" -> "cbA")
|
||||||
|
def invert_string(string):
|
||||||
|
return string[::-1]
|
||||||
|
|
||||||
|
|
||||||
|
# Все буквы сделать заглавными (например "aBc" -> "ABC")
|
||||||
|
def to_upper_string(string):
|
||||||
|
# Что должна возвращать функция?
|
||||||
|
str1 = ""
|
||||||
|
|
||||||
|
# Проводим вычисления
|
||||||
|
for c in string:
|
||||||
|
# Проверить, какая буква
|
||||||
|
if 97 <= ord(c) <= 122:
|
||||||
|
# Если маленькая - то превращаем в большую и добавляем в итоговую строку
|
||||||
|
str1 += chr(ord(c) - 32)
|
||||||
|
else:
|
||||||
|
# Если уже большая - то перенимаем букву в итоговую строку
|
||||||
|
# А если вообще не буква?! - Также перенимаем без изменений
|
||||||
|
str1 += c
|
||||||
|
|
||||||
|
# Вернуть значение
|
||||||
|
return str1
|
||||||
|
|
||||||
|
|
||||||
|
# Все буквы сделать прописными (например "aBc" -> "abc")
|
||||||
|
def to_lower_string(string):
|
||||||
|
str1 = ""
|
||||||
|
|
||||||
|
for x in string:
|
||||||
|
if 65 <= ord(x) <= 90:
|
||||||
|
str1 += chr(ord(x) + 32)
|
||||||
|
else:
|
||||||
|
str1 += x
|
||||||
|
|
||||||
|
return str1
|
||||||
|
|
||||||
|
|
||||||
|
# Проверить, является ли строка палиндромом (независимо от больших/маленьких букв)
|
||||||
|
def check_palindrome(string):
|
||||||
|
new_string = to_upper_string(string)
|
||||||
|
return new_string == invert_string(new_string)
|
||||||
|
|
||||||
|
|
||||||
|
# Проверить, является ли строка палиндромом (независимо от больших/маленьких букв и знаков пунктуации/пробелов)
|
||||||
|
def check_palindrome_escaped(string):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# "Ручной" аналог функции split()
|
||||||
|
def split_string(string, separator):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# "Ручной" аналог функции join()
|
||||||
|
def join_array(array, separator):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
def verifier(test_name, actual, expected):
|
||||||
|
print(test_name)
|
||||||
|
if actual != expected:
|
||||||
|
print("=======> FAILED! <=======")
|
||||||
|
print(f"Got value <{actual}>")
|
||||||
|
print(f"Expected value is <{expected}>")
|
||||||
|
else:
|
||||||
|
print("PASSED")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
test_array1 = [6, 4, 7, -3, 6, -1, 5, 8, 4, -6, 8, 3, 6, 4, -7, 21, 6, 4, -1, 1]
|
||||||
|
test_array2 = [987, 342, -876, 182, -6534, 998, -11, 334, 0, 6654, -9901, 333, 111, 664]
|
||||||
|
test_array3 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
|
||||||
|
|
||||||
|
test_string1 = "The World is not enough"
|
||||||
|
test_string2 = "Testing is key"
|
||||||
|
|
||||||
|
test_palindrome1 = "Sir, I demand, I am a maid named Iris"
|
||||||
|
test_palindrome2 = "Satire: Veritas"
|
||||||
|
test_palindrome3 = "Saippuakivikauppias"
|
||||||
|
|
||||||
|
test_split1 = "1, 2, 3, 4, 5, 6, 7, 8, 9"
|
||||||
|
test_split2 = "1 2 3 4 5 6 7 8 9"
|
||||||
|
test_split3 = "bagahajemanbdneorijahdhrea4"
|
||||||
|
|
||||||
|
test_array4 = test_split1.split(',')
|
||||||
|
test_array5 = test_split2.split(' ')
|
||||||
|
test_array6 = test_split3.split('a')
|
||||||
|
|
||||||
|
sum_array_tests = [test_array1, test_array2, test_array3, [], [0]]
|
||||||
|
string_tests = [test_string1, test_string2, test_palindrome1, test_palindrome2, test_palindrome3, '']
|
||||||
|
palindrome_tests = [test_string1, test_string2, test_palindrome1, test_palindrome2, test_palindrome3, '']
|
||||||
|
split_string_tests = [test_split1, test_split2, test_split3, test_string1, test_string2, '']
|
||||||
|
join_array_tests = [test_array4, test_array5, test_array6, [], ['']]
|
||||||
|
|
||||||
|
for i in range(len(sum_array_tests)):
|
||||||
|
verifier(f"SUM_ARRAY TEST {i+1}", sum_array(sum_array_tests[i]), sum(sum_array_tests[i]))
|
||||||
|
|
||||||
|
for i in range(len(sum_array_tests)):
|
||||||
|
verifier(f"SUM_DIFF_ARRAY TEST {i+1}", sum_diff_array(sum_array_tests[i]), sum(sum_array_tests[i][0::2]) - sum(sum_array_tests[i][1::2]))
|
||||||
|
|
||||||
|
for i in range(len(sum_array_tests)):
|
||||||
|
if len(sum_array_tests[i]) == 0:
|
||||||
|
verifier(f"MAX_MUL_MIN_ARRAY TEST {i + 1}", max_mul_min_array(sum_array_tests[i]), 0)
|
||||||
|
else:
|
||||||
|
verifier(f"MAX_MUL_MIN_ARRAY TEST {i+1}", max_mul_min_array(sum_array_tests[i]), max(sum_array_tests[i]) * min(sum_array_tests[i]))
|
||||||
|
|
||||||
|
for i in range(len(string_tests)):
|
||||||
|
verifier(f"INVERT_STRING TEST {i+1}", invert_string(string_tests[i]), string_tests[i][::-1])
|
||||||
|
|
||||||
|
for i in range(len(string_tests)):
|
||||||
|
verifier(f"TO_UPPER_STRING TEST {i+1}", to_upper_string(string_tests[i]), string_tests[i].upper())
|
||||||
|
|
||||||
|
for i in range(len(string_tests)):
|
||||||
|
verifier(f"TO_LOWER_STRING TEST {i+1}", to_lower_string(string_tests[i]), string_tests[i].lower())
|
||||||
|
|
||||||
|
for i in range(len(palindrome_tests)):
|
||||||
|
verifier(f"CHECK_PALINDROME TEST {i+1}",
|
||||||
|
check_palindrome(palindrome_tests[i]),
|
||||||
|
(palindrome_tests[i].lower() == palindrome_tests[i].lower()[::-1]))
|
||||||
|
|
||||||
|
for i in range(len(palindrome_tests)):
|
||||||
|
val = "".join(e for e in palindrome_tests[i] if e.isalpha())
|
||||||
|
verifier(f"CHECK_PALINDROME_ESCAPED TEST {i+1}",
|
||||||
|
check_palindrome_escaped(palindrome_tests[i]),
|
||||||
|
(val.lower() == val.lower()[::-1]))
|
||||||
|
|
||||||
|
for i in range(len(split_string_tests)):
|
||||||
|
separator = ','
|
||||||
|
verifier(f"SPLIT_STRING (SEPARATOR='{separator}') TEST {i+1}",
|
||||||
|
split_string(split_string_tests[i], separator),
|
||||||
|
split_string_tests[i].split(separator))
|
||||||
|
|
||||||
|
for i in range(len(split_string_tests)):
|
||||||
|
separator = ' '
|
||||||
|
verifier(f"SPLIT_STRING (SEPARATOR='{separator}') TEST {i+1}",
|
||||||
|
split_string(split_string_tests[i], separator),
|
||||||
|
split_string_tests[i].split(separator))
|
||||||
|
|
||||||
|
for i in range(len(join_array_tests)):
|
||||||
|
separator = '#'
|
||||||
|
verifier(f"JOIN_ARRAY (SEPARATOR='{separator}') TEST {i+1}", join_array(join_array_tests[i], separator), separator.join(join_array_tests[i]))
|
||||||
|
|
||||||
|
for i in range(len(join_array_tests)):
|
||||||
|
separator = ''
|
||||||
|
verifier(f"JOIN_ARRAY (SEPARATOR='{separator}') TEST {i+1}", join_array(join_array_tests[i], separator), separator.join(join_array_tests[i]))
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Game.iml" filepath="$PROJECT_DIR$/.idea/Game.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
class Player:
|
||||||
|
|
||||||
|
def __init__(self, color):
|
||||||
|
self.color = color
|
||||||
|
self.position = -1
|
||||||
|
self.skip = False
|
||||||
|
self.dices = []
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
from Player import Player
|
from Player import Player
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,9 +23,6 @@ def load(file):
|
||||||
return b
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def level_menu():
|
def level_menu():
|
||||||
for i in range(1, len(levels) + 1):
|
for i in range(1, len(levels) + 1):
|
||||||
print(f'{i}. Level {i}')
|
print(f'{i}. Level {i}')
|
||||||
|
@ -130,6 +125,6 @@ def run(level, runs):
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
levels = ['level1.txt', 'level2.txt', 'level3.txt', 'level4.txt', 'level5.txt', 'level6.txt']
|
levels = ['level_1.txt', 'level_2.txt', 'level_3.txt', 'level_4.txt', 'level_5.txt']
|
||||||
#random.seed()
|
#random.seed()
|
||||||
main_menu_loop()
|
main_menu_loop()
|
Loading…
Reference in New Issue