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
spayn [35]
3 years ago
6

The first and second numbers in the Fibonacci sequence are both 1. After that, each subsequent number is the sum of the two prec

eding numbers. The first several numbers in the sequence are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, etc. Write a function named fib that takes a positive integer parameter and returns the number at that position of the Fibonacci sequence. For example fib(1)
Computers and Technology
1 answer:
vlabodo [156]3 years ago
7 0

Answer:

In Python:

def fib(nterms):

   n1, n2 = 1, 1

   count = 0

   while count < nterms:

       term = n1

       nth = n1 + n2

       n1 = n2

       n2 = nth

       count += 1

   return term

Explanation:

This line defines the function

def fib(nterms):

This line initializes the first and second terms to 1

   n1, n2 = 1, 1

This line initializes the Fibonacci count to 0

   count = 0

The following while loops gets the number at the position of nterms

<em>   while count < nterms: </em>

<em>        term = n1 </em>

<em>        nth = n1 + n2 </em>

<em>        n1 = n2 </em>

<em>        n2 = nth </em>

<em>        count += 1 </em>

This returns the Fibonnaci term

   return term

You might be interested in
#Draw patterns using fibonacci
agasfer [191]

Answer:

yidRYoYORoydzyrozoyrsoyraoyeahplhDogdaoyeayeoayorahdlHDLgksOyeayeazhldhdlHkdOyaoyaerhaahdLhKDoywaeya9yaeya9eeY9ey9

7 0
3 years ago
Which of the following tasks requires you to use the Tabs option?
Monica [59]
Indenting a paragraph :)
7 0
4 years ago
What does the opacity effect do
coldgirl [10]

Opacity is the extent to which something blocks light. You can change the opacity of layers, filters, and effects so that more (or less) of the underlying image shows through.

6 0
3 years ago
Read 2 more answers
The best advice for setting a study session is
ExtremeBDS [4]
To take breaks and not do all the work at once.
3 0
3 years ago
* Discuss how an individual’s access to a wide range of online services affects their ability to operate safely in the digital w
ehidna [41]
Honestly, no online service is safe anymore these days...People and even the government can get hacked easily with today's technology.You can search someone easily on websites like Google or Facebook and even read someone's tweets on Twitter because their account is not private. But what's the point of saying private if they can easily get hacked by someone. There is no safety these days that is why you have to be careful with what you post on the internet in general.In these times people have to be cautious to not slip and fall off the iceberg surrounded by sharks.
4 0
3 years ago
Other questions:
  • What is one way to maintain Internet safety? a) avoid interacting with people on the Internet. B) avoid giving out information a
    7·1 answer
  • One of the ways to create a horizontal navigation menu from an unordered list is to a. set the display property of the element w
    6·1 answer
  • To combat piracy, many software publishers require users to type in a(n) ____ code, a sequence of numbers and letters in order t
    10·1 answer
  • Assume that a picture is represented on a monitor screen by a rectangular array containing 2048 columns and 1536 rows of pixels.
    12·1 answer
  • i got a set of headphones and when i plug them into my speakers the right side only works how do i fix the left side of them
    12·1 answer
  • Where could an identity theft access your personal information?
    9·2 answers
  • Grooves and polished surfaces on desert pebbles are most likely caused by
    10·1 answer
  • How do you compare text on different pages of a document?
    14·1 answer
  • The term generally used to describe storage systems that function at high speeds is:
    12·1 answer
  • When the user types into a Textbox control, the text is stored in the control's __________ property.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!