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
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.
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
( 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...
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.
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
how many 4 digit numbers divisible by 5 can be formed from 0,1,3,5,7,9 if repetition is...
how many 4 digit numbers divisible by 5 can be formed from 0,1,3,5,7,9 if repetition is not allowed and 0 and 1 Can not be next to each other. i can do the first part. there are 2 cases case 1, the number ends in zero. 5 x 4 x 3 x 1. but i dont know how to account for the zero and one not being able to be next to each other. i counted 12 possible numbers that...
How many numbers between 9 and 3009 are divisible by 2, 5, or 11? Please answer...
How many numbers between 9 and 3009 are divisible by 2, 5, or 11? Please answer correctly. Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT