Sponsor

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 Counter

l1=[1,2,3,4]
s=
set()


for 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(150)):
    
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=125
ans=0
rem=0
while n>0:
    rem=n%10
    
ans=ans+rem
    n=n//10
print(ans)

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

Ans=


n=int(input("enter number :"))

n1=0
n2=1
print(n1)
print(n2)

for 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 in range(2num):
            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 in range(n,1,-1):
    for 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  math
x1=5
x2=10
y1=7
y2=16

form=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_left


def BinarySearch(ax):
    i = bisect_left(ax)
    if i != len(a) and a[i] == x:
        return i
    else:
        return -1
a = [12448]
x = int(4)
res = BinarySearch(ax)
if res == -1:
    print(x"is absent")

else:
    print("First occurrence of"x"is present at"res)

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

Other Posts :-

  1. Android First App With SoftwareTechIT
  2. Switch Activity Using Intent on Button click
  3. Mumbai v/s Corona Virus afrer LockDown Traveling and films vlog/blog
  4. Activity and Activity Life Cycle with SoftwareTechIT
  1. After 12th Course and Career Options
  2. SoftwareTechIT YouTube Channel Videos Points And Videos
  3. Android Tutorial on Button Click Event And Toast Message with SoftwareTechIT
  4. Points And Videos learn android app development with softwaretechit
  5. Introduction To fragment and Fragment Life Cycle With Example
  6. Views & ViewGroups Learn With | SoftwareTechIT (English)
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,

Post a Comment

0 Comments