Print Nth Fibonacci Number
EasyPractice library · +10 XPbasicsloopsarithmetic
The Fibonacci sequence is a sequence where each number is the sum of the two preceding ones, starting from 0 and 1. The sequence goes: 0, 1, 1, 2, 3, 5, 8, 13, 21, ... Given a non-negative integer N, print the Nth Fibonacci number (where the 0th Fibonacci number is 0, the 1st is 1, and so on).
Input
A single non-negative integer N.
Output
The Nth Fibonacci number.
Constraints
0 <= N <= 30
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
10
Output
55
The 10th Fibonacci number is 55.
Example 2
Input
0
Output
0
The 0th Fibonacci number is 0.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
10
Example 2 input
0