TUPLE 1. Write a Python program that creates a tuple storing first 9 terms of Fibonacci series. fib=(0,) n=int(input('Please enter a number ')) a,b=0,1 for i in range(n): a, b = b, a+b fib=fib+(a,) print(fib) 2. (a) Write a program that receives the index and returns the corresponding value. fib=(0,) n=int(input('Please enter a number ')) a,b=0,1 for i in range(n): a, b = b, a+b fib=fib+(a,) print(fib) readInput=int(input("Enter an index ")) print("Element at index ",readInput," is : ",fib[readInput]) (b) Write a program that receives a Fibonacci term and returns a number telling which term it is for instance, if you pass 3, it returns 5, telling it is 5th term; for 8, it returns 7. fib=(0,) n=int(input('Please enter a number ')) a,b=0,1 for i in range(n): a, b = b, a+b fib=fib+(a,) print(fib) readInput=int(input("Enter a fibonacci term: ")) print(fib.index(readInput)+1) 3. Write a pr...
Comments
Post a Comment