Question

In: Advanced Math

Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than...

Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than 1000. The program prints the resulting number. You may only use while loops.

Use python language

Solutions

Expert Solution

Python Script (Be careful with indentation):

from math import floor

f = [1,1] # vector that will increase with generated Fibonacci numbers
indx = 2;
count = 0 # counter for number of required Fibonacci numbers
while True:
f.append(f[indx-1] + f[indx-2]) # generate next Fibonacci number and append to list
if f[indx] >= 1000:
# considering only numbers less than 1000
break
if floor(f[indx]/3) == f[indx]/3:
# if divisible by 3
count += 1
indx += 1
print('Count =', count)

Screenshot of the above script:

Output:

Count = 4


Related Solutions

Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than...
Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than 1000. The program prints the resulting number. You may only use while loops. Use python language
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers...
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers and the recursive formula please refer to problem 5 of Chapter 2 at page 81 in the text-book.) The program asks the user to input an integer and outputs the corresponding Fibonacci number. For example, if the user inputs 4, the program outputs the fifth Fibonacci number, which is 3. Introduce two local variables in the recursion function (suppose we call it fib(n)), one...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Java Write a program that displays all the numbers from 100 to 200 that are divisible...
Java Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both Make sure all instructions and outputs for the user are explicit
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by...
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by sum of the digits in them. For example, 2924 is divisible by (2+9+2+4 = 17). Your program should display all these possible numbers in the given range, and each number should be separated from the other by a space.
How to write an assembly program that simply counts how many A’s, C’s, T’s, and G’s...
How to write an assembly program that simply counts how many A’s, C’s, T’s, and G’s the input string contain.
Write an algorithm that print all numbers that are divisible by 3 between 1000 and 2000
Write an algorithm that print all numbers that are divisible by 3 between 1000 and 2000
How many numbers between 1 and 500 (including 1 and 500) are not divisible by any...
How many numbers between 1 and 500 (including 1 and 500) are not divisible by any of 3, 5, or 7? Your solution should be worked all the way out into an integer.
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence...
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … what is the initialization of a, b, and d? - a b d 1 ? ? 1 2 ? ? 1 3 1 1 2 4 1 2 3 5 2 3 5 6 3 5 8 7 5 8 13 wrong initialization - a b d 1 0 1 1 2...
Write a MIPS assembly program to calculate the Fibonacci numbers from 1..n using the recursive method....
Write a MIPS assembly program to calculate the Fibonacci numbers from 1..n using the recursive method. The definition of a Fibonacci number is F(n) = F(n-1) + F(n-2). The implementation must follow the following guidelines: Prompt the user for a number n Allocate heap memory to hold the exact number of elements in the Fibonacci sequence for n Implement recursive Fibonacci method as a subprogram Print the Fibonacci sequence array
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT