Friday, 18 June 2021

Top 5000 python programs examples with solutions - Part 3

Program 21:

How to write  a program to calculate negative numbers in a list?

list=[1,2,3,4,5,-1,-2,-3,-4,-8]
if 0 not in list:
    list.append(0)
list=sorted(list)
pos=list.index(0)
print(pos)

Read more »

Labels:

Tuesday, 8 June 2021

Top 5000 python programs examples with solutions - Part 4

Program 41:

How to write  a program to print Fibonacci series of a number?

def fib(n):
   p, q = 0, 1
   while(p < n):
       yield p
       p, q = q, p + q
k=int(input('Enter the Number\n'))
for i in fib(k):
   print(i)

 

Read more »

Labels: