Assignment 4
Assignment 4
XI-G
ASSIGNMENT 4
#question 1
s1=input('enter a string:')
ch=input('enter a character:')
stcount=s1.count(ch)
print(stcount)
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
enter a string:nikunj
enter a character:n
#question 2
a=input('enter a string')
print('original string', a)
newa=" "
for i in a:
if i in 'aeiouAEIOU':
newa+='*'
else:
newa+=i
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
#question 3
s1=input('enter a string')
print('original is',s1)
revs1=s1[::-1]
if s1==revs1:
print('it is a palindrome')
else:
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
it is not a palindrome
#question 4
s1=input('enter a string')
print('original is',s1)
news1=s1.title()
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
#question 5
s1=input('enter a string')
ch=input('enter a character')
newst=s1.replace(ch,'')
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
enter a stringNikunj
enter a characterN
#question 6
s1=input('enter a string')
s=0
for i in s1:
if i.isdigit():
s+=int(i)
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
#question 7
s1=input('enter a string')
newst=s1.replace(' ','-')
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
enter a stringN I K U N J T I W A R I
#question 8
st=input('enter a string')
digitcount=0
lowercount=0
uppercount=0
wordcount=0
spacecount=0
specialcount=0
for i in st:
digitcount+=1
lowercount+=1
uppercount+=1
wordcount+=1
spacecount+=1
else:
specialcount+=1
OUTPUT
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32