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
sp2606 [1]
3 years ago
13

A python script to print fibonacci series first 20 elements

Computers and Technology
1 answer:
madreJ [45]3 years ago
5 0

Answer:

   nterms =20

   # first two terms

   n1, n2 = 0, 1

   count = 0

   # check if the number of terms is valid

   if nterms <= 0:

      print("Please enter a positive integer")

   elif nterms == 1:

      print("Fibonacci sequence upto",nterms,":")

      print(n1)

   else:

      print("Fibonacci sequence:")

      while count < nterms:

          print(n1)

          nth = n1 + n2

          # update values

          n1 = n2

          n2 = nth

          count += 1

Explanation:

Here, we store the number of terms in nterms. We initialize the first term to 0 and the second term to 1.

If the number of terms is more than 2, we use a while loop to find the next term in the sequence by adding the preceding two terms. We then interchange the variables (update it) and continue on with the process.

<em>output:</em>

Fibonacci sequence:

0

1

1

2

3

5

8

You might be interested in
why does my Minecraft screen this "play and "settings" instead of the regular layout with singleplayer, multiplayer, and options
ratelena [41]

Answer:

Are you Minecraft Java or Minecraft Bedrock?

Are you updated to the latest Firmware?

8 0
3 years ago
Read 2 more answers
Can you block someone on Brainly?
dexar [7]
Yes, you can! If they are bothering you I would recommend you report them first. Check out this Brainly article https://brainly.in/question/1233133 :-)
8 0
3 years ago
Read 2 more answers
10 facts about turbines
sp2606 [1]
They provide wind energy
 Wind power consists of turning energy from the wind to other energy forms.
Windmills have been in use since 2000 B.C.
developed in Persia
Wind energy is the fastest growing mode of electricity
Wind farms can be constructed in off shore locations
Wind energy is renewable and pollution free source of energy
Most of the modern wind turbines have 3 blades
The largest wind turbine in the world is located in US in Hawaii
The first modern wind turbine was built in 1940’s in Vermont.
8 0
3 years ago
Read 2 more answers
Will give Brainliest 100 points answer only if you know
katrin [286]
There are five basic programming elements, or operations: input, output, arithmetic, conditional, and looping. Every program uses at least two of these.

The description of a programming language is usually split into the two components of syntax (form) and semantics (meaning).

Input: getting data and commands into the computer

Output:getting your results out of the computer

Arithmetic: performing mathematical calculations on your data

Conditional: testing to see if the condition is true or false

Looping: cycling through a set of instructions until some condition is met
7 0
3 years ago
Read 2 more answers
Write a function called middle(string str) that returns a string containing the middle character in str if the length of str is
jenyasd209 [6]

Answer:

Note: a) If the length of the string is odd there will be two middle characters.

Explanation:

b) If the length of the string is even there will be one middle character. There was a problem connecting to the server. Please check your connection and try running the trinket again.

3 0
2 years ago
Other questions:
  • What was the first<br> 1:search engine<br> 2:website<br> 3:time the internet started
    6·1 answer
  • When a user runs an application, what transfers from a storage device to memory?
    15·1 answer
  • Which formula best expresses your monthly ending balance?
    12·1 answer
  • ___ apps can allow you to lock your mobile device and sim card remotely.
    15·1 answer
  • NEED BY 15 MINUTES PLEASE! WILL MARK BRAINLIEST!You can create special effects in an image using a camera or a photo-editing too
    5·1 answer
  • Rob used Track Changes to suggest changes in Jack's document. Jack agrees with some edits and disagrees with others. What should
    14·1 answer
  • Every presentation should have a beginning, a middle, and an end.
    10·1 answer
  • Which country has the most common features of analogue and digital computer​
    6·1 answer
  • Draw and implement of an organization which have 125 employees. use the following features 1.email services 2.lan communication
    8·1 answer
  • An optical drive randomly becomes unavailable, and after replacing the drive, the technician now suspects that the drive may not
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!