Computer Science
Define a function which accepts n as an argument and prints Fibonacci series till n.
Python
Python Modules
4 Likes
Answer
def print_fibonacci(n):
a, b = 0, 1
while a <= n:
print(a, end=' ')
a, b = b, a + b
n = int(input("Enter a number: "))
print_fibonacci(n)Output
Enter a number: 10
0 1 1 2 3 5 8
Answered By
3 Likes
Related Questions
Consider the amount of donations received by a charitable organization given as under:
donations = [100, 60, 70, 900, 100, 200, 500, 500, 503, 600, 1000, 1200]
Now write a Python program to calculate the average amount obtained and median of the above data.
Write a Python program to generate a random number between 0 and 9.
Consider the temperature given below for the month of June in North India. Calculate the average temperature and median value. This temperature gets dipped with a variation of 20°C in the month of December. Write a Python program to calculate the changed median value and average temperature.
Location Temperature (in °C) Delhi 41 Shimla 32 Chandigarh 43 Rohtak 40 Srinagar 28 Sri Ganganagar 45 Create a menu-driven program using user-defined functions to implement a calculator that performs the following:
(a) Basic arithmetic operations (+, −, *, /)
(b) log10(x), sin(x), cos(x)