Consider the following program: n = int(input()) while n != 1: print(n) if n % 2
ID: 3913034 • Letter: C
Question
Consider the following program:
n = int(input())
while n != 1:
print(n)
if n % 2 == 0:
n = n // 2
else:
n = n * 3 + 1
print("done")
Which of the following statements is correct?
Depending on the user input, the program sometimes prints a sequence of numbers followed by "done" and sometimes it prints an infinite sequenes of numbers without ever printing "done".
Depending on the user input, the program prints different sequences of numbers but it never prints "done".
Depending on the user input, the program prints different sequences of numbers and finally prints "done".
None of the other statements are true. (No one really knows what this program does.)
Explanation / Answer
Depending on the user input, the program sometimes prints a sequence of numbers followed by "done" and sometimes it prints an infinite sequenes of numbers without ever printing "done".
it terminates for all positive numbers but for 0 and negative integers it will go in infinite loop.