Find the largest/smallest number in a list/tuple | Write a recursive code to compute the nth Fibonacci number.

Find the largest/smallest number in a list/tuple

# creating empty list 

list1 = [] 

  

# asking number of elements to put in list 

num = int(input("Enter number of elements in list: ")) 

  

# iterating till num to append elements in list 

for i in range(1, num + 1): 

    ele= int(input("Enter elements: ")) 

    list1.append(ele) 

      

# print maximum element 

print("Largest element is:", max(list1))


# print minimum element 

print("Smallest element is:", min(list1))


Program 2

Write a recursive code to compute the nth Fibonacci number.

 

def fibonacci(n):

     if n == 0:

       return 0

     elif n == 1:

       return 1

     else:

       return(fibonacci(n-2) + fibonacci(n-1))


nterms = int(input("Please enter the Range Number: "))


# check if the number of terms is valid

if nterms <= 0:

   print("Plese enter a positive integer")

else:

   print("Fibonacci sequence:")

   for i in range(nterms):

       print(fibonacci(i),end=' ')

 


If you any doubts, Please let me know

Previous Post Next Post

Contact Form