[go: up one dir, main page]

0% found this document useful (0 votes)
6 views5 pages

Assignment 4

The document contains a series of Python code assignments by Nikunj Tiwari, showcasing various string manipulation techniques. Each question includes user input prompts and outputs for tasks such as counting characters, replacing vowels, checking for palindromes, and analyzing string properties. The document demonstrates practical applications of string methods and control structures in Python.

Uploaded by

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

Assignment 4

The document contains a series of Python code assignments by Nikunj Tiwari, showcasing various string manipulation techniques. Each question includes user input prompts and outputs for tasks such as counting characters, replacing vowels, checking for palindromes, and analyzing string properties. The document demonstrates practical applications of string methods and control structures in Python.

Uploaded by

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

NIKUNJ TIWARI

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

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/1.py ================

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

print(‘new sting is’,newa)

OUTPUT

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/2.py ================


enter a stringnikunj

original string nikunj

new sting is n*k*nj

#question 3

s1=input('enter a string')

print('original is',s1)

revs1=s1[::-1]

if s1==revs1:

print('it is a palindrome')

else:

print('it is not a palindrome')

OUTPUT

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/3.py ================

enter a string nikunj tiwari

original is nikunj tiwari

it is not a palindrome

#question 4

s1=input('enter a string')

print('original is',s1)

news1=s1.title()

print('new string is ',news1)

OUTPUT

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/4.py ================

enter a stringhello world

original is hello world


new string is Hello World

#question 5

s1=input('enter a string')

ch=input('enter a character')

print('the original str is',s1)

newst=s1.replace(ch,'')

print('the new str is',newst)

OUTPUT

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/5.py ================

enter a stringNikunj

enter a characterN

the original str is Nikunj

the new str is ikunj

#question 6

s1=input('enter a string')

print('the original str is',s1)

s=0

for i in s1:

if i.isdigit():

s+=int(i)

print('the sum is ',s)

OUTPUT

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/6.py ================

enter a string wow its year 2025

the original str is wow its year 2025


the sum is 9

#question 7

s1=input('enter a string')

print('the original str is',s1)

newst=s1.replace(' ','-')

print('new string is ',newst)

OUTPUT

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/7.py ================

enter a stringN I K U N J T I W A R I

the original str is N I K U N J T I W A R I

new string is N-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:

if i>='0' and i<='9':

digitcount+=1

elif i>='a' and i<='z':

lowercount+=1

elif i>='A' and i<='Z':

uppercount+=1

elif i==" ":

wordcount+=1
spacecount+=1

else:

specialcount+=1

print('total digits are',digitcount)

print('total lowercase are',lowercount)

print('total uppercase are',uppercount)

print('total words are',wordcount+1)

print('total spaces are',spacecount)

print('total special character are',specialcount)

print('total characters are',digitcount+lowercount+uppercount+spacecount+specialcount)

OUTPUT

Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:/Users/nikun/OneDrive/Desktop/8.py ================

enter a stringNikunj Tiwari

total digits are 0

total lowercase are 10

total uppercase are 2

total words are 2

total spaces are 1

total special character are 0

total characters are 13

You might also like