Posts

Showing posts from January, 2020

Pyramid pattern

Pyramid pattern using for number n=int(input("enter n") for i in range(0,n):     for j in range(0,n-i-1):        print(end=" ")     for j in range(0,i+1):         print("*",end=" ") print()

Bubble Sort

Sort the given numbers using bubble sort Input:    How many numbers you have to sort     n=4 input=[78,54,66,70,77] , Output:       sorted array is:         54 66 70 77 78 Program:  n = int (input()) list=[] for i in range(n):        k=int (input())        list . append(k) for i in range(len (list) ):           for j in range(0, len (list)-i-1):            if list[j] > list[j+1]:                 list[j].list[j+1]=list[j+1].list[j] print("Sorted array is:") for I in range(len(list)):         printf(list[i],ends=" ")

Factorial

Find the factorial for given number using python Input:      given number is 8 Output:       output is 40320 def fact(n): if n == 1: return n; else: return n * fact(n-1) print(fact(4))

Python

Swap the two file lines from one to one using python Input:      create two txt files Output:      interchange the lines of two file.(i.e.)sample txt file lines is stored to sample2.txt file Program: a=open("sample.txt") x=a . read() print(x) a . close() b=open("sample2 . txt") y=b . read() print(y) b . close() c=open("sample . txt" , "w") c=write(y) print(c) c . close() d=open("sample2 . txt" , "w") d . write(x) print(d) d . close()