0% found this document useful (0 votes)
5 views3 pages

10 Intermediate Python Programs

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

10 Intermediate Python Programs

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10 Python Assignment Programs (Intermediate

Level)

Program 1: Prime Number Check


Code:
n=7
flag=True
for i in range(2,n):
if n%i==0:
flag=False
break
print('Prime' if flag else 'Not Prime')
Output:
Prime

Program 2: Fibonacci Series


Code:
a,b=0,1
for i in range(5):
print(a)
a,b=b,a+b
Output:
01123

Program 3: Reverse a Number


Code:
n=1234
rev=0
while n>0:
rev=rev*10+n%10
n//=10
print(rev)
Output:
4321

Program 4: Palindrome Number


Code:
n=121
t=n
rev=0
while n>0:
rev=rev*10+n%10
n//=10
print('Palindrome' if rev==t else 'Not Palindrome')
Output:
Palindrome

Program 5: Armstrong Number


Code:
n=153
t=n
s=0
while n>0:
d=n%10
s+=d**3
n//=10
print('Armstrong' if s==t else 'Not Armstrong')
Output:
Armstrong

Program 6: Count Vowels in String


Code:
s='education'
count=0
for ch in s:
if ch in 'aeiou':
count+=1
print(count)
Output:
5

Program 7: Linear Search


Code:
a=[2,4,6,8,10]
x=6
found=False
for i in a:
if i==x:
found=True
print('Found' if found else 'Not Found')
Output:
Found

Program 8: Bubble Sort


Code:
a=[5,1,4,2]
n=len(a)
for i in range(n):
for j in range(0,n-i-1):
if a[j]>a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
print(a)
Output:
[1, 2, 4, 5]

Program 9: Frequency of Characters


Code:
s='banana'
f={}
for ch in s:
f[ch]=[Link](ch,0)+1
print(f)
Output:
{'b':1,'a':3,'n':2}

Program 10: Simple Calculator


Code:
a=10
b=5
print('Add:',a+b)
print('Sub:',a-b)
print('Mul:',a*b)
print('Div:',a/b)
Output:
Add:15 Sub:5 Mul:50 Div:2.0

You might also like