1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Illusion [34]
2 years ago
8

Write a function that takes as input a single integer parameter n and computes the nth Fibonacci Sequence number. The Fibonacci

sequence first two terms are 1 and 1. (so, if n = 2, your function should return 1). From there, the previous two values are summed to come up with the next result in the sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc.
Computers and Technology
1 answer:
RSB [31]2 years ago
4 0

Answer:

Following are the code to this question:

def Fibonacci(n):#defining a method Fibonacci that accept a parameter

   a = 1#defining a variable a that holds a value 1

   b = 1#defining a variable b that holds a value 1

   if n <= 0:# Use if to check n value

       print("invalid number")#print message

   elif n == 2:#defining elif that check n equal to 2

        return 1#return 1

   else:#defining else block

       print(a)#print value of a

       print(b)#print value of b

       for i in range(2,n):#defining for loop to calculate series

           s = a + b# add value in s variable

           a = b # interchange value

           b = s# hold s value

           print(s)#print s value

Fibonacci(10)#calling method

Output:

1

1

2

3

5

8

13

21

34

55

Explanation:

In the above-given program code, a method "Fibonacci" is defined, which holds a value "n" in its parameter, and inside the method two-variable "a and b" is defined, that holds a value "1".

  • In the next step, if a block is defined that checks n value is less than equal to 0, it will print "invalid number" as a message.
  • In the elif, it checks n value is equal to 2 it will return a value that is 1.
  • In the else block, it will calculate the Fibonacci series and print its value.
You might be interested in
Advantages of Linux include_____.
Assoli18 [71]

Answer:

The ability to tweak an application, and i think security. I've barely scratched the surface of linux so my answer may not be 100% accurate

Explanation:

8 0
3 years ago
Is a network where connected devices are located within the same building.
Nesterboy [21]

Answer:

Answer A

Explanation:

Answer A, because, metropolitan area network is a network within a city or town and wide area network usually connects many cities. So, both C & D are spread on a wide area.

8 0
3 years ago
Read 2 more answers
Which of the following is a key component to your individual internet safety? government regulations
nexus9112 [7]
It is government regulations and acceptable use policy
3 0
3 years ago
Arrange the Jumbled letters 1.eilf ngrihsa ________________ 2.cersityu ourreecs ________________ 3. ngrihsa ________________ 4.
Alisiya [41]

Answer:

1. file sharing

2. security recourse

3.sharing

4.communication

5.flexible access

Explanation:

-

5 0
3 years ago
Woah my favorite character got arrested
olasank [31]

Not sure how to answer this. But shaggy was quite amazing.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Dial-up connections can be made over a(n) ____ line or phone line. isdn dsl ipx tcp/ip
    12·1 answer
  • When you first open office calc, the most recently saved spreadsheet opens up. A) true B) false
    14·1 answer
  • Home communication involves controlling systems such as heating, cooling, and security.
    11·1 answer
  • PLEASE HELP ASAP!!
    11·2 answers
  • Autumn suffers from nocturnal dyspnea. This term describes a breathing condition but using the prefixes to translate, it means:
    5·1 answer
  • You manage a network that uses switches. In the lobby of your building, there are three RJ45 ports connected to a switch. You wa
    5·1 answer
  • Which command os used to find a particular word in a document ?<br>​
    9·2 answers
  • Need help ASAP.<br> I am so lost.
    5·1 answer
  • What type of databases is not limited by the data’s physical location?
    7·1 answer
  • Which privacy protection uses four colors to indicate the expected sharing limitations that are to be applied by recipients of t
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!