[go: up one dir, main page]

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

Ak Python p2

The document contains practical exercises involving Python code that utilizes regular expressions. It includes tasks such as checking if a string ends with 'tion', finding alphabets in a given string, and verifying if a string starts with 'mo' and ends with 'le'. Additionally, it covers counting occurrences of the letter 'a', checking for vowels or specific numbers, and determining if a string ends with a number.

Uploaded by

Sajid Ahmed
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)
5 views3 pages

Ak Python p2

The document contains practical exercises involving Python code that utilizes regular expressions. It includes tasks such as checking if a string ends with 'tion', finding alphabets in a given string, and verifying if a string starts with 'mo' and ends with 'le'. Additionally, it covers counting occurrences of the letter 'a', checking for vowels or specific numbers, and determining if a string ends with a number.

Uploaded by

Sajid Ahmed
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/ 3

Practical 2

NAME- SAJID AHMED Roll no-001 DATE-4/2/2023

Aim: Programs based on regular expressions


1. Using regular expression write the Python code to accept a string from
user and search whether it ends with “tion”.
CODE:
import re as r
s=input("Enter a String: ")
a=r.findall("tion$",s)
if a:
print("Found")
else:
pr8int("Not found")

OUTPUT:

2. Given a string “abbreviation” Using regular expression write the Python


code to accept alphabets from user and find whether the alphabets are part
of the string.
CODE:
import re as r
t="Abbreviation"
b=input("Enter a Alphabet: ")
a=r.findall(b,t)
if a:
print("Yes Alphabet found")
else:
print("Alphabet not found in string")

OUTPUT:

1
3. Using regular expression write the Python code to accept a string from
user and find whether it starts with ‘mo’ and ends with ‘le’ and any 2
characters in between them.
CODE:
import re as r
t=input("Enter a string: ")
a=r.findall("mo..le",t)
if a :9
print("Found")
else:
print("Not found")

OUTPUT:

4. Using regular expression accept a string from user and display the
number of times alphabet ‘a’ is present in it.
CODE:
import re as r
c=input("Enter a string: ")
a=r.findall("a+",c)
print(len(a))

OUTPUT:

2
5. Using regular expression write the Python code to accept a string from
user and check whether it has any vowels or number 6,7,8,9.
CODE:
import re as r
c=input("Enter a string: ")
a=r.findall("[a,e,i,o,u,6,7,8,9]",c)
if a:
print("Found")
else:
print("Not Found")

OUTPUT:

6. Using regular expression write the Python code to accept a string from
user and check whether it ends with a number.
CODE:
import re as r
c=input("Enter a string: ")
a=r.findall("[1,2,3,4,5,6,7,8,9,0]$",c)
if a:
print("Found")
else:
print("Not Found")

OUTPUT:

You might also like