46.8k views
5 votes
Which input for variable c causes "Done" to be output next? c = 'y' while c == 'y': # Do something print('Enter y to continue, n to quit: ', end=' ') C= input() print('Done'); Click on the Correct Response A) 'y' only B) Any value other than 'y' C) 'n' only D) No such value (infinite loop)

1 Answer

7 votes

The input for variable `c` that causes "Done" to be output next is B) Any value other than 'y'.

In the provided code, there is a `while` loop with the condition `while c == 'y':`. This means the loop will continue as long as the value of `c` is equal to 'y'. Inside the loop, it prints the message "Enter y to continue, n to quit: " and then waits for user input which is assigned to the variable `C` (note the capitalization difference between `c` and `C`, which may lead to some confusion but doesn't affect the loop condition).

If you input 'y' for the variable `C`, the loop will continue, and it will print "Enter y to continue, n to quit: " again, waiting for your input. However, if you input any value other than 'y', the condition `c == 'y'` will be false and the loop will terminate. After the loop, it will print "Done".

So, in this code, entering 'y' for `C` is the only input that causes the loop to continue, while entering any other value for `C` will cause the loop to exit and "Done" to be printed.

Therefore, the Option B is correct.

User Loaf
by
8.1k points

No related questions found