Вопрос задан 29.11.2023 в 21:42. Предмет Информатика. Спрашивает Панков Илья.

Вася запустил программу и получил ошибку. Он подозревает, что где-то не так поставил кавычки.

Дана строка в кавычках. Совпадает ли закрывающая кавычка с открывающей? Выведи "ДА" или "НЕТ". Ввод Вывод "Строка" ДА "Данные' НЕТ
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Богданова Виктория.

n = input()

if n[0] == n[-1]:

print("ДА")

else:

print("НЕТ")

Не знаю, проходили Вы "Срезы" или нет, сделал с ними. Если не проходили, то хотя бы циклы проходили, сделаю с циклом?

Если помог, поставь пожалуйста - ❤ и отметку "Лучший ответ"


0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Task: Check if the closing quotation mark matches the opening quotation mark in a given string.

To determine if the closing quotation mark matches the opening quotation mark in a given string, we can use a simple algorithm. Here's how we can approach this:

1. Read the input string. 2. Initialize a stack to keep track of opening quotation marks. 3. Iterate through each character in the string. - If the character is an opening quotation mark (single or double), push it onto the stack. - If the character is a closing quotation mark (single or double), check if the stack is empty or if the top of the stack is a matching opening quotation mark. If it is, pop the opening quotation mark from the stack. - If the character is neither an opening nor a closing quotation mark, continue to the next character. 4. After iterating through all the characters, check if the stack is empty. If it is, then the closing quotation mark matches the opening quotation mark. Otherwise, they do not match.

Let's implement this algorithm in Python:

```python def check_quotation_marks(string): stack = [] opening_quotes = ['"', "'"] closing_quotes = ['"', "'"]

for char in string: if char in opening_quotes: stack.append(char) elif char in closing_quotes: if len(stack) == 0 or stack[-1] != char: return "НЕТ" stack.pop()

if len(stack) == 0: return "ДА" else: return "НЕТ"

# Example usage: input_string = "Строка" result = check_quotation_marks(input_string) print(result) ```

In this example, the input string is "Строка". The function `check_quotation_marks` will return "ДА" because the closing quotation mark matches the opening quotation mark.

Please note that this is a basic implementation and does not account for nested or escaped quotation marks. If you need to handle more complex cases, additional logic may be required.

Let me know if you need any further assistance!

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос