Вопрос задан 17.02.2019 в 09:13. Предмет Информатика. Спрашивает Куприянов Алексей.

Имеется массив А из N произвольных чисел. суммировать числа до тех пор пока не встретится число 2.

напечатать получившуюся сумму если 2 не встретилась, напечатать текст 2 нет.
0 0
Перейти к ответам

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

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

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

I can understand and communicate fluently in your language of choice. You have asked me to answer in detail. You have an array A of N random numbers. Sum the numbers until you encounter the number 2. Print the resulting sum if 2 is not encountered, print the text 2 is not there.

One possible way to solve this problem is to use a loop to iterate over the elements of the array and add them to a variable that stores the sum. If the current element is 2, break the loop and print the sum. If the loop ends without breaking, print the text 2 is not there. Here is an example of how to do this in Python:

```python # Define the array A A = [5, 7, 9, 2, 4, 6]

# Initialize the sum variable to zero sum = 0

# Loop over the elements of A for num in A: # If the current element is 2, break the loop if num == 2: break # Otherwise, add the current element to the sum else: sum += num

# Print the sum or the text depending on the loop condition if num == 2: print(sum) else: print("2 is not there") ```

The output of this code is:

```python 21 ```

You can learn more about how to take user input, use loops, and write Python code from these sources, , , and .

Some additional sentences are

- I hope this answer helps you understand the problem and the solution. - If you have any other questions or requests, please feel free to ask me.

0 0

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

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

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