Reputation: 1
I found this python3 code in a tutorial case. I don't understand how the sys.stdin.read() works on a mac. The input command starts but I cannot close it. If I press ctrl + D, apparently nothing happens. If I press cmd + D, I get exit code 0.
import sys
def get_fibonacci_last_digit_naive(n):
if n <= 1:
return n
previous = 0
current = 1
for _ in range(n - 1):
previous, current = current, previous + current
return current % 10
if __name__ == '__main__':
input = sys.stdin.read()
n = int(input)
print(get_fibonacci_last_digit_naive(n))
Upvotes: 0
Views: 744
Reputation: 165
I assume you understand how sys.stdin.read()
itself works.
On a Mac, the CMD
key is the equivalent of the Ctrl
key on a Windows PC. That is why Mac expects the user to press CMD
+ D
to finish their entry.
Upvotes: 1