0% found this document useful (0 votes)
25 views26 pages

PDF&Rendition 1

Uploaded by

annudevi298
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)
25 views26 pages

PDF&Rendition 1

Uploaded by

annudevi298
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
You are on page 1/ 26

Name

anu
Course
‘O’LEVEL
Fathe’S Name
Mr.rammehar
Roll No
660
Submiited TO
Mrs Geeta Mam
Q.1 write a program to count the number of digit in
entered number.
SORCE CODE
n=int(input("enter any number"))
count=0
while(n>0):
count=count+1
n=n//10
print("the number of digits in the number are:",count)

OUTPUT :-
Q.2 write a program to print ASCII code for
entered string or message.

string=input("enter string to encode:")


print("ASCLL code for string:")
for ch in string:
print(ch,"ASCLL code is=",ord(ch),end="/n")

OUTPUT :-
Q.3 write a program to check entered number is a
pefect or not.
SORCE CODE
num=int(input("enter a number"))
sum=0
for i in range(1,num):
if(num%i==0):
sum=sum+i
if (sum==num):
print("the numis perfect number")
else:
print("the num is not a prefact number")

OUTPUT :-
Q.4 write a program to find the factors of
a number.
SORCE CODE:-
num=int(input("enter a number"))
for i in range(1,num+1):
if num%i==0:
print(i)

OUTPUT :-
Q.5 write a program to print inverted
str pattern.
SORCE CODE :-
num=int(input("enter a number"))
for i in range(num,0,-1):
print((num-i)* ' ' + i * '*')

OUTPUT :-
Q.6 Write a program to print fibonacciseries.
SORCE CODE :-
number=int(input("enter a number"))
f1=0
f2=1
print(f1)
print(f2)
for i in range(1,number):
f3=f1+f2
print(f3)
f1,f2=f2,f3

OUTPUT :-
Q.7 write a program to print all the
prime number within a given range.
SORUCE CODE :-
n=int(input("enter any number"))
for i in range(2,n+1):
c=0
for j in range(2,i//2+1):
if(i%j==0):
c=c+1
if(c<=0):
print(i,end=' ')
OUTPUT :-
Q.8 write a program to find armstrong
number between 100to 500.
SOURCE CODE :-
for i in range(100,500,1):
sum=0
temp=i
while temp>0:
rem=temp%10
sum+=rem**3
temp//=10
if i==sum:
print(i,"is armstrong number")

OUTPUT :-
Q.9 write a program to principal
amount,rate and time and caluate the
compound interest amount.
SORCE CODE :-
p=float(input("enter the principal
amount"))
t=float(input("enter the number of
year"))
r=float(input("enter the rate of
interest"))
ci=p*(pow((1+r/100),t))
print("comound interest :{}".format(ci))

OUTPUT :-
Q.10 write a program to find cumulative
sum of a list.
SOURCE CODE :-
# cumulativa sum
def fun(a):
new=[]
sum=0
for i in a:
sum+=i
new.append(a)
return new

lists=[10,20,30,40,50]
print("new list:",fun(lists))
OUTPUT :-
Q.11write a program that takes in a
sentence as input and display the
number of words,number of capital
letters,number of small letters,number
of digit and number of special symbols.
Source code :-
str1=input("enter a sentence")
word=len(str1.split())
u,l,n,s=0,0,0,0
for i in range(len(str1)):
if str1[i]>='A' and str1[i]<='Z':u+=1
elif str1[i]>='a' and str1[i]<='z':l+1
elif str1[i]>='0' and str1[i]<='9':n+1
else:s+=1
print("original strings:",str1)
print("the number of words in string
are:" + str(word))
print('\nupper case characters:',u)
print('lower case characters:',l)
print('number case:',n)
print('special case charactrs:',s)

OUTPUT :-
Q.12 write a program that takes as
input from the user and computes the
frequency of each letter .use a variable
of dictionary type to maintain and show
the frequency of each letter.
SOURCE CODE :-
string =input("enter any srting")
a={ }
for i in string:
if i in a:
a[i]+=1
else:
a[i]=1
print(str(a))
OUTPUT :-
Q.13 write a program to replace
consonant with next immediate
consonant alphabetically that means
‘b’with ‘c’,’c’ with ‘d’ and similarly for
‘b’ with ‘c’,’c’ with ‘d’,……,’z’ with ‘b’
.they vowel should remain unchanged.
SOURCE CODE :-
def vowel(ch):
if(ch != 'a' and ch != 'e' and ch != 'i'
and ch != 'o' and ch != 'u'):
return False
return True
def replace(str):
for i in range(len(str)):
if (vowel(str[i])==False):
if(str[i]=='z'):
str[i]='b'
else:
str[i]=chr(ord(str[i])+1)
if(vowel(str[i])==True):

str[i]=chr(ord(str[i])+1);
return ''.join(str);
str="olevel"
print(replace(list(str)))

OUTPUT :-
Q.14 write a program to find product of
two numbers with repetitive addition by
using recursion.
SOURCE CODE :-
def mul(f1,f2):
if(f1<f2):
return mul(f2,f1)
elif(f2!=0):
return (f1+mul(f1,f2-1))
else:
return 0
f1=5
f2=10
print(mul(f1,f2))
OUTPUT :-
Q.15 write a program to compute
highest common factor(hcf).
SOURCE CODE :-
def hcf(x,y):
if x>y:
small=y
else:
small=x
for i in range(1,small+1):
if((x%i==0)and(y%i==0)):
hc=i
return hc
number1=5
number2=10
print(hcf(number1,number2))
OUTPUT :-
Q.16 write a python function that takes
two lists and return true if they have at
least one common item.
SOURCE CODE :-
def comman(list1,list2):
result=False
for x in list1:
for y in list2:
if x==y:
result=True
return result
print(comman([1,2,3,4,5],[6,7,8,9]))
print(comman([1,2,3,4,5],[6,7,8,9]))
OUTPUT :-
Q.17 write a program to print Fibonacci
series upto term n by using recursion.
SOURCE CODE :-
def fun(n):
if n<=1:
return n
else:
return(fun(n-1)+fun(n-2))
nterms=int(input("enter the number of
terms"))
if nterms<=0:
print("plese enter a positive integer")
else:
print("fibonacci series:")
for i in range(nterms):
print(fun)
OUTPUT :-
Q.18 write a python program that reads
a text file and count the number of
times a certain letter appears in the text
file.
SOURCE CODE :-
name=input("enter file name")
letter=input("enter letter whice you
want to search")
c=0
with open(name,'r')as n:
for line in n:
words=line.split()
for i in words:
for let in i:
if(let==letter):
c=c+1
print(c)
OUTPUT :-
Q.19 write a program in python to
accept two file from the user and
append the content of the second file
with the content of the first file.
SOURCE CODE :-
firstfile=input("enter the name of first
file")
scondfile=input("enter the name of
scondfile")
f1=open(firstfile,'r')
f2=open(scondfile,'r')
print('content of first file before
appending-',f1.read())
print('content of scond file before
appending-',f2.read())
f1.close()
f2.close()
f1=open(firstfile,'a+')
f2=open(scondfile,'r')
f1.write(f2.read())
f1.seek(0)
f2.seek(0)
print('content of first file after
appending-',f1.read())
print('content of scond file after
appending-',f2.read())
f1.close()
f2.close()
OUTPUT :-
Q.20 write a program to read file word
by word.
SOURCE CODE :-
with open ('first.txt','r') as file:
for line in file:
for word in line.split():
print(word)

OUTPUT :-
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy