Question

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By...

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1,2,3,5,8,13,21,34,55,89,... By considering the terms in the Fibonacci sequence whose values do not exceed 1000, find the sum of the all the terms up to 300, by writing a python program.

Homework Answers

Answer #1

Note: I have a little confusion in the code, that up to which terms I need to sum in the series. However I have make a program that will add the elements till we don't encounter a no. greater than 300. If limit needs to be changed, by just changing the no. i the while loop will work.

Program:

#fibonacci list storing first 300 terms of series
fibonacci = [1, 2] + [0]*298

#generating all 300 terms by adding previous two each time
for i in range(2,298):
    fibonacci[i] = fibonacci[i-1]+fibonacci[i-2]
    
#since we need to find sum, we'll use while loop
i = 0

#sum variable will store the sum of the series
sum = 0

#we'll traverse the list till we don't get a no. in series
#greater than 300
while fibonacci[i]<300:
    
    #adding the no.
    sum += fibonacci[i]
    
    #for moving to the next value
    i+=1
    
#print statement
print("The sum of the series of first {} terms: {}".format(i+1, sum))

Output:

The sum of the series of first 13 terms: 608

Leave a comment if face any kind of doubt!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ARM Assembly Code The Fibonacci Sequence is a series of integers. The first two numbers in...
ARM Assembly Code The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not...
Except for the first two terms,each term of the sequence 1000,x,1000-x,... is obtained by subtracting the...
Except for the first two terms,each term of the sequence 1000,x,1000-x,... is obtained by subtracting the preceding term from the one before that. The last term of the sequence is the first negative term. What positive integer x produces a sequence of maximum length?
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
FOR PROBLEMS 1 AND 2. Use the sequence formulas. Carry out your calculations to the final...
FOR PROBLEMS 1 AND 2. Use the sequence formulas. Carry out your calculations to the final number. Round the results to 1 decimal place.    1. Consider the sequence: 1/2, 1, 2, 4, 8, a. Find the 30th term of the sequence. b. Find the sum of the first 30 terms of the sequence. 2. You give your daughter a piggy bank with $2 in it. She puts $5 in it the next week and each week thereafter. How much...
Draft a contract not to exceed two pages in length, providing all essential terms, providing for...
Draft a contract not to exceed two pages in length, providing all essential terms, providing for all foreseeable contingencies that you can, and delineating remedies for breach based on the following facts: You own a new restaurant called "Bill's Mexican and Irish Food". You have agreed to buy all the buffalo meat you need from "Fresh Exotic Meats ". You plan to only use them for all your buffalo meat as long as they meet your requirements that the buffalo...
Gilroy’s Casting Company, which has historically specialized in aluminum casting is considering adding a new bronze...
Gilroy’s Casting Company, which has historically specialized in aluminum casting is considering adding a new bronze casting line to its production facility. Over the past several years the artistic community in Park City and along the Wasatch front has significantly increased and the company has received an increasing number of requests to do bronze castings. The casting line would be set up in unused space in Gilroy’s main plant. The equipment would cost approximately $200,000, plus another $10,000 for shipping...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
JAVA Bike shares are becoming increasingly common in cities in the United States. Commuters have been...
JAVA Bike shares are becoming increasingly common in cities in the United States. Commuters have been using bike sharing as a method of transportation for the flexibility, cost savings, exercise, and a myriad of other benefits. While being quite successful, many bike shares are still relatively new and have room for optimization. To help with the optimization process, we want to analyze bike share data from the city of Los Angeles. The first step of the process is to collect...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT