Question

Write a Python program stored in a file q2.py that asks for a starting number and...

Write a Python program stored in a file q2.py that asks for a starting number and an ending number, and then prints all the Fibonacci numbers between them (and including the starting and ending numbers, if they are also Fibonacci numbers). Each Fibonacci number, must be separated by a space.

Example:

Enter starting number : 5
Enter ending number : 500

10 Fibonacci numbers between 5 and 500 are :
5 8 13 21 34 55 89 144 233 377

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

n1 = 0

n2 = 1

start = int(input("Enter starting number : "))

end = int(input("Enter ending number : "))

if (start <= n1 <= end):

print(n1, end = " ")

if (start <= n2 <= end):

print(n2, end = " ")

while True:

nth = n1 + n2

n1 = n2

n2 = nth

if (start <= nth <= end):

print(nth, end = " ")

if (nth > end):

break

n1 = 0 Enter starting number : 5 Enter ending number : 500 5 8 13 21 34 55 89 144 233 377 n2 1 2 3 start = int(input (Enter

Add a comment
Know the answer?
Add Answer to:
Write a Python program stored in a file q2.py that asks for a starting number and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program stored in a file q3.py that asks for the prices of items...

    Write a Python program stored in a file q3.py that asks for the prices of items and your money amount as input, and prints the options of items along with cost as output. Enter list of prices : 7 3 9 12 26 17 8 9 Enter dollar amount : 16 You have total 8 options Option 1: You can buy item 1 and item 2 with $10 .0. Option 2: You can buy item 1 and item 3 with...

  • please write in python Write a program that asks for beginning and ending number. The program...

    please write in python Write a program that asks for beginning and ending number. The program generates a set of 20 random numbers between the numbers and displays a count of each number generated. Sample output Enter starting and ending number separated by comma: 5, 25 5 occurs 2 times 7 occurs 1 time 8 occurs 1 time 10 occurs 2 times 12 occurs 1 time 13 occurs 2 time 15 occurs 5 times 16 occurs 1 time 20 occurs...

  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

  • Using Java 1. The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, ....Each number in...

    Using Java 1. The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, ....Each number in the sequence (after the first two) is the sum of the previous two. Write a program that computes and outputs the nth Fibonacci number, where n is a value entered by the user. The Fibonacci Sequence 1,1,2,3,5,8,13.21,34,55,89,144,233,377... 1+12 13+2134 1+23 21+34-55 2-35 34+55-09 3+58 56+89144 5+8=13 89+144233 8+13-21 144+233 377 5

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

  • Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 =...

    Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 = Fi + Fi+1, where i = 0, 1, 2, . . . . In other words, each number is the sum of the previous two numbers. Write a recursive function definition in C++ that has one parameter n of type int and that returns the n-th Fibonacci number. You can call this function inside the main function to print the Fibonacci numbers. Sample Input...

  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • C# - Using Visual Studio 2017/2019 The Fibonacci sequence is a numerical sequence that follows a...

    C# - Using Visual Studio 2017/2019 The Fibonacci sequence is a numerical sequence that follows a simple pattern: 1,1, 2, 3, 5, 8, 13, 21, 34, 55, By definition, the first two numbers are 1 and 1, and each subsequent number is the sum of the previous two. For your program, you will ask the user to enter a number, n, and then calculate and display the values of the Fibonacci sequence to the nth position. ==sample output== Enter an...

  • Write a C program to compute and print Fibonacci values for some integers. You can assume...

    Write a C program to compute and print Fibonacci values for some integers. You can assume that all input numbers are positive integers. The Fibonacci numbers are defined as follows: The first two Fibonacci numbers are 1 and 1. Any Fibonacci number after the first two numbers is the sum of its two predecessors. The Fibonacci numbers can be listed as the following sequence:         1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... It is clear...

  • Write a program in python using lists or tuples that asks for two positive integers n1...

    Write a program in python using lists or tuples that asks for two positive integers n1 and n2 and prints out all the numbers that are divisible by 7 but are not a multiple of 5 within the range [n1,n2] (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT