# Python Program assignment wise first Assignment | Python For Beginners | Python Programs for beginner

Assignment 1

Set A]

1) Write a program which accepts 5 integer values and prints “DUPLICATES” if any of the

values entered are duplicates otherwise it prints “ALL UNIQUE”.

Example: Let 5 integers are (32, 45, 90, 45, 6) then output “DUPLICATES” to be printed.

Ans=

``from  collections import Counterl1=[1,2,3,4]s=set()for i in range(0,len(l1)):    s.add(l1[i])if(len(l1)!=len(s)):    print("dublicates")else:    print("All Unique")`   `

2) Write a program which accepts an integer value as command line and print “Ok” if value is

between 1 to 50 (both inclusive) otherwise it prints ”Out of range”

Ans=

``n=int(input("enter the 1 to 50 :"))if(n in range(1, 50)):    print("ok")else:    print("number is not between 1 to 50")`    `

3) Write a program which finds sum of digits of a number.

Example n=125 then output is 8 (1+2+5).

Ans=

``n=125ans=0rem=0while n>0:    rem=n%10    ans=ans+rem    n=n//10print(ans)`  `

4) Write a program which prints Fibonacci series of a number.

Ans=

``n=int(input("enter number :"))n1=0n2=1print(n1)print(n2)for i in range(2,n+1):    n3=n1+n2    n1=n2    n2=n3    print(n3)`    `

Set B]

1) Write a program which accept an integer value ‘n’ and display all prime numbers till ‘n’.

Ans=

``low = int(input("Enter lower number"))high = int(input("Enter higher number"))for num in range(low,high+1):    if num > 1:        for i in range(2, num):            if (num % i) == 0:                break        else:            print(num)`    `

2) Write a program to display following pattern.

1 2 3 4

1 2 3

1 2

1

Ans=

``n=int(input("enter num"))for i in range(n,1,-1):    for j in range(1,i):        print(j,"",end="")    print()`    `

3) Write a program that finds distance between 2 points (x1,y1) and (x2,y2) using the equation

Ans=

``import  mathx1=5x2=10y1=7y2=16form=math.sqrt((x2-x1)**2+(y2-y1))print("ans",form)`    `

Set C]

1) Write a binary search function which searches an item in a sorted list. The function should

return the index of element to be searched in the list.

Ans=

``from bisect import bisect_leftdef BinarySearch(a, x):    i = bisect_left(a, x)    if i != len(a) and a[i] == x:        return i    else:        return -1a = [1, 2, 4, 4, 8]x = int(4)res = BinarySearch(a, x)if res == -1:    print(x, "is absent")else:    print("First occurrence of", x, "is present at", res)`    `

### Thank You For Visiting!!!! ###

## Other Posts :-

python programs for practice,python programming examples pdf,python program to add two numbers,python tutorial,cool python programs,python programs for interview,python programming examples advanced,python programming for the absolute beginner,python tutorial pdf,python tutorial w3school,python tutorial for beginners,python tutorial youtube,python tutorial point,python tutorial geeksforgeeks,python tutorial - javatpoint,python tutorial free,python download,,python tutorial
python w3schools,python compiler,learn python,python snake,python basics,python for beginners,