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
When using Regedit to browse through the registry, the key that is highlighted is the ________, and its value entries are visibl
Dafna11 [192]

Answer:

Active keys

Explanation:

When using Regedit to browse through the registry, the key that is highlighted is the ACTIVE KEY and its value entries are visible in the contents pane on the right.

It allows authorized users to view the Windows registry and make changes

and also provide to every user for the activation of Windows so that only the actual buyers of the Windows can activate it.

5 0
3 years ago
You entered the following line of code in IDLE.
AlexFokin [52]

Guess is a string. By default the input function returns string types.

8 0
3 years ago
Read 2 more answers
Constructors have the same name as the ____.1. data members2. member methods3. class4. package
Svetradugi [14.3K]

Answer:

(3) option is the correct answer.

Explanation:

Constructors need to initialize the object in the memory. "To declare the Constructor for any class the user needs to specify the constructor name which is already the class name". This is an object-oriented language guideline.

It is because the object is created by the name of the class and Constructor is used to allocate the memory for the object. hence Constructor is created by the name of the class.

For example--

                       class test //class name test

                      {

                               test() //created a constructor with class name "test"

                               {

                               }

                      }

In the above example class name and constructor name are same if it not then it will gives a error.

Another option is not valid for the answer to the above problem because-

  • Option 1 is wrong because, for any class, the data member is a type of variable, which is used to store the data and is accessed with the help of an object.
  • Option 2 is wrong because, for any class, member function is a type of user function used to accessed the variable and expressions.
  • Option 4 is wrong because, package is a set used to hold classes and interfaces.

8 0
3 years ago
10 sentences about computer parts.
Ahat [919]
One computer part is the CPU, it’s a piece of hardware the last allows your computer to access and interact all the applications and programs. The first ever CPU chip was invented around 4 decades ago. The keyboard is another computer part and it allows the user to type letters and numbers. There are about 104 keys on a keyboard and there are different parts in it. Some of the parts include, control keys, function keys, navigation keys, numeric keypad, and so on. A mouse is another device used with the keyboard to position the cursor. It’s a hand held device that detects two-dimensional motion relative to a surface. This motion is typically translated Into the motion of a pointer on a display, which allows a smooth control of the graphical user. Memory is a device to store all of your information and saved data. The motherboard is the backbone that tied together the computers components at one spot.
6 0
2 years ago
Given the lists list1 and list2, not necessarily of the same length, create a new list consisting of alternating elements of lis
tester [92]

Answer:

The following code is written in Python Programming Language.

Program:

list1=[1,2,3]

 # initialized the list type variable

list2=[4,5,6,7,8]

  # initialized the list type variable

list3=[]

   # initialized the empty list type variable

for j in range(max(len(list1), len(list2))):   #set for loop

 if j<len(list1):

  #set if statement

   list3.append(list1[j])

  #value of list1 appends in list3  

 if j<len(list2):

   #set if statement

   list3.append(list2[j])

  #value of list2 append in list3

print(list3)    #print the list of list3

Output:

[1, 4, 2, 5, 3, 6, 7, 8]

Explanation:

Here, we define three list type variables "list1", "list2", "list3" and we assign value in only first two variables "list1" to [1, 2, 3] and "list2" to [4, 5, 6, 7, 8] and third list is empty.

Then, we set the for loop and pass the condition inside it we pass two if conditions, in first one we compare the list1 from variable "j" inside it the value in list1 will append in list3, and in second one we compare "j" with list two and follow the same process.

After all, we print the list of the variable "list3".

5 0
3 years ago
Other questions:
  • Create a dictionary named letter_counts that contains each letter and the number of times it occurs in string1. Challenge: Lette
    14·1 answer
  • why is there a need of properly interpreting teacher's/manufacturer's specifications before operating any food processing equipm
    9·1 answer
  • Which of the following browsers was introduced with windows 10?
    10·1 answer
  • Which sentence is correctly punctuated? WILL GIVE YU MONEY GIVE ME YOUR CASH APP PLS
    12·2 answers
  • Why do certain words change color in Python?
    6·1 answer
  • 4.11 lesson practice quizz need help on 2 and 3
    5·1 answer
  • Python program oranges and apples 3.4.6 copy and paste would be nice
    7·1 answer
  • Do you know the energy unit question?
    10·1 answer
  • What is an outcome in a game? Don't search google just give me an answer
    9·1 answer
  • Define the terms network, LAN, WAN, and Internet.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!