18.2k views
2 votes
N = int(input(""Enter a number, 17 to stop.""))

sum = 0

while (n != 17):
if (n % 2 == 0):
sum = sum + n
n = int(input(""Enter a number, 17 to stop.""))

print(""Sum: "" + str(sum))
This is an example of a(n) ____ loop."

A) Infinite
B) For
C) Do-While
D) While

User YoungFrog
by
8.6k points

2 Answers

2 votes

Final answer:

The code given in the question exemplifies a While loop that sums even numbers until the number 17 is entered, which ends the loop.

Step-by-step explanation:

The code snippet you've provided is an example of a While loop. This type of loop continuously executes a block of code as long as the given condition, in this case n != 17, remains true. The loop contains a conditional statement that checks if the number n is even, in which case it is added to the variable sum. The process repeats until the user enters the number 17, which breaks the loop and outputs the sum of all entered even numbers.

User Gyozo Kudor
by
8.9k points
7 votes

Answer:

It is D, a while loop.

Step-by-step explanation:

"while (n != 17):"

This is the key term to look for, and for a bit of a more detailed explanation, it's running the code under the "while" statement when n!= 17.

User Stephen Rudolph
by
7.6k points