74 lines
1.4 KiB
Python
74 lines
1.4 KiB
Python
def myString(str, char):
|
||
count = 0
|
||
|
||
for c in str:
|
||
if char == c:
|
||
count += 1
|
||
|
||
return count
|
||
|
||
|
||
def mySum(array):
|
||
sum = 0
|
||
for a in array:
|
||
sum += a
|
||
|
||
return sum
|
||
|
||
|
||
def myMax(array):
|
||
max = array[0]
|
||
|
||
for b in array:
|
||
if b > max:
|
||
max = b
|
||
|
||
return max
|
||
|
||
|
||
def myMin(array):
|
||
min = array[0]
|
||
|
||
for b in array:
|
||
if b <= min:
|
||
min = b
|
||
|
||
return min
|
||
|
||
|
||
def menu():
|
||
print("1. Сумма")
|
||
print("2. Максимум")
|
||
print("3. Минимум")
|
||
print("4. Подсчет кол-ва символов")
|
||
print("5. Выход")
|
||
|
||
|
||
A = [3, 4, 5, 6]
|
||
mystr = 'С Новым Кодом! Ура!'
|
||
char = '!'
|
||
|
||
while True:
|
||
menu()
|
||
inp = input()
|
||
if inp.isnumeric():
|
||
op = int(inp)
|
||
if 1 <= op <= 5:
|
||
if op == 1:
|
||
result = mySum(A)
|
||
elif op == 2:
|
||
result = myMax(A)
|
||
elif op == 3:
|
||
result = myMin(A)
|
||
elif op == 4:
|
||
result = myString(mystr, char)
|
||
elif op == 5:
|
||
print("Программа завершена")
|
||
break
|
||
|
||
print(result)
|
||
else:
|
||
print("Операции под номером " + str(op) + " не существует!")
|
||
else:
|
||
print("Вы ввели какую-то глупость!")
|