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]
3 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]3 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
1.1. (30 points) Write a program to calculate the average number of cars sold by a car agency over a period of years for the fir
mario62 [17]

Answer:

count = 0

months = 0

years = int(input("Enter the number of years: "))

for year in range(1, years+1):

   cars_sold = int(input("Enter the number of cars sold in first six months: "))

   count += cars_sold

   months += 6

print("Number of months: " + str(months))

print("Number of cars sold in total: " + str(count))

print("Average number of cars sold per month: " + str(count / months))

Explanation:

Initialize the variables

Ask the user for the number of years

Create a for loop that iterates depending on the given number of years

Ask the user for the number of cars sold in the first six months of the year

Increment the count by given number and increment the months by 6 after each iteration

Print the months, count and, average

8 0
3 years ago
What is printed by the following program provided all necessary standard header files are included? Explain each line of the out
Ostrovityanka [42]

<u>Output:</u>

f1 in A

f2 in A

f1 in B

f2 in A

f1 in A

f2 in A

f1 in B

f2 in B  

<u>Explanation:</u>

In this snippet, the code makes use of virtual functions. A virtual function is defined as a function that is defined in the base class and redefined in the derived class. If the derived function accesses the virtual function, the program will get executed with the derived class’s version of the function.

In this code, we define the virtual function f1() in class A and also redefine it in class B which is the derived class of A. While executing the program, the function g which takes the object b (class B’s object) as a parameter. It will print class B’s version of f1() rather than class A’s version. This is working off the virtual function.

8 0
3 years ago
A single line text input control with an initial value as +971
Nezavi [6.7K]

Answer:

What's about this initial value equal to 971

Explanation:

\sqrt{2}

8 0
3 years ago
James, a system administrator, is tasked to update the BIOS and firmware of the computer in his organization. What are the reaso
Xelga [282]

Answer:

One reason to update BIOS and firmware is to ensure they support new hardware like CPU model or graphic card. In some cases, the updates can also resolve overheating issue or motherboard issue.  

However, this is not always the case that we must update the BIOS every time there is a new release because the latest update may cause problem to existing system as well.

As a general rule, only when there are some problems with the existing BIOS and firmware, we are only required to update them.

7 0
3 years ago
This standard library function returns a random oating-point number within a specied range of values.
IgorLugansk [536]

Answer:

Uniform

Explanation:

The uniform is a standard library function in python that returns a random floating number withing a specified range of values. Floating numbers which are integer numbers separated by a dot or decimal point from the fractional part. It is part of the random module. it is implemented as

Because it is defined in the random module, random module needs to be imported for uniform to be available for use.

import random

random.uniform(lowest point or highest number, highest point or highest number)

5 0
3 years ago
Other questions:
  • Reflexes are basically "hard-wired" into the CNS. Anatomically, the basis of a reflex is an afferent neuron that synapses direct
    10·1 answer
  • When the speaker compares dream memories to fall leaves that are hard to catch,what feeling does the simile suggest?
    14·2 answers
  • Declare an array named scores of twenty-five elements of type int .
    7·1 answer
  • How is multiprogramming implemented using virtual memory?
    10·1 answer
  • In the context of web and network privacy, an acceptable use policy is _____.
    15·1 answer
  • What does API stand for
    7·2 answers
  • How Do you get Splatoon two for free
    6·2 answers
  • Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th
    8·1 answer
  • I am trying to do a python code quiz for school, the basic requirements for the quiz are: the quiz MUST have 10 questions
    15·2 answers
  • Which option in PowerPoint allows users to configure the number of columns and rows manually, using numerical values?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!