Created
July 20, 2022 16:01
-
-
Save gmakc-094423/7068b96cd83add52b9de9b057459a335 to your computer and use it in GitHub Desktop.
Домашнее задание к семинару № 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
def InputNumbers(inputText): | |
is_OK = False | |
while not is_OK: | |
try: | |
number = int(input(f"{inputText}")) | |
is_OK = True | |
except ValueError: | |
print("Какое-то неправильное число!") | |
return number | |
def fill_list(diap): | |
target_list = [] | |
for i in range(diap): | |
target_list.append(randint(-diap, diap)) | |
return target_list | |
def check_list(num, diap, target_list): | |
if -diap < num < diap: | |
for i in target_list: | |
if i == num: | |
print("Yes") | |
break | |
else: | |
print("No") | |
else: | |
print("число вне пределов ") | |
diapazon = InputNumbers("Введите диапазон (от -х до +х) и он же размер списка: ") | |
target_list = fill_list(diapazon) | |
print(target_list) | |
check_number = InputNumbers("Введите проверяемое число: ") | |
check_list(check_number, diapazon + 1, target_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_list = ["qwe", "asd", "zxc", "qwe", "ertqwe"] | |
print(f"список: {test_list}") | |
test_item = input("Введите искомую строку: ") | |
def check_list(test_list, test_item): | |
count = 0 | |
for i in range(len(test_list)): | |
if test_list[i] == test_item: | |
count += 1 | |
if count == 2: | |
return i | |
else: | |
return -1 | |
print(f"ответ: {check_list(test_list, test_item)}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def min_text(item_list): | |
count = 0 | |
word = item_list[0] | |
for i in item_list: | |
if i == word: | |
count += 1 | |
item_list.remove(i) | |
print(f"{word} = {count}") | |
input_text = "a aa abC aa ac abc bcd a" | |
input_text = input_text.lower() | |
new_list = input_text.split() | |
while len(new_list) != 0: | |
min_text(new_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment