0% found this document useful (0 votes)
17 views6 pages

Tushar AP 5.

Uploaded by

tusharsingh06.ts
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)
17 views6 pages

Tushar AP 5.

Uploaded by

tusharsingh06.ts
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/ 6

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 5(A)
Student Name: Tushar Singh UID: 22BCS15923
Branch: CSE Section/Group: 622/B
Semester: 5 Date of Performance: 3/09/24
Subject Name: Advanced Programming Lab-1 Subject Code: 22CSP-314

1. Title: Pangrams

2. Aim: Pangram is a string that contains every letter of the alphabet. Given a sentence
determine whether it is a pangram in the English alphabet. Ignore case. Return either
pangram or not program as appropriate

3. Objective:

Complete the function pangrams in the editor below. It should return the string
pangram if the input string is a pangram. Otherwise, it should return not
pangram.pangrams has the following parameter(s):
string s: a string to test
It returns either pangram or not pangram

4. Algorithm:

 Input: A String.

 Convert: Convert the string to lowercase.

 Create Set: Create a set of all lowercase alphabet letters.

 Compare Sets: Check if the set of lowercase letters is subset of the character in the input
string.

 Output: If all alphabet letters are present, return “pangram”; otherwise, return “not
pangram”.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5. Implementation/Code

import math
import os
import random
import re
import sys
def pangrams(s):
s = s.lower()
alphabet_set = set('abcdefghijklmnopqrstuvwxyz')
s_set = set(s)
if alphabet_set <= s_set:
return "pangram"
else:
return "not pangram"
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = pangrams(s)
fptr.write(result + '\n')
fptr.close()

6. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

7. Learning Outcomes:

 Learn how to convert a string to lowercase using lower().


 Understand the use of sets to store and compare unique
characters.
 Identify pangrams by checking if a sentence contains
every letter of the alphabet.
 Use set operations to efficiently compare character sets in
Python.
 Implement basic input/output handling and file writing in
Python.
8. Time Complexity: O(n)

9. Space Complexity: O(n)


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment 5(B)
Student Name: Tushar Singh UID: 22BCS15923
Branch: CSE Section/Group: 622/B
Semester: 5 Date of Performance:03/09/24
Subject Name: Advanced Programming Lab-1 Subject Code: 22CSP-314

1. Title: Find a String

2. Aim: You have to print the number of times that the substring occurs in the given
string. String traversal will take place from left to right, not from right to left.
NOTE: String letters are case-sensitive.
Input Format: The first line of input contains the original string. The next
line contains the substring.
3. Objective:
In this challenge, the user enters a string and a substring. You have to print
the number of times that the substring occurs in the given string. String
traversal will take place from left to right, not from right to left.

4. Algorithm:

 Initialize a counter count to 0.

 Iterate through the string up to the point where there’s still enough space
left to check for the substring.

 At each position i, it checks if the substring matches the portion of the


string starting at i and continuing for the length of the substring.

 If a match is found, it increments the count.

 Finally, the function returns the count of matches.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Implementation/Code
def count_substring(string,
sub_string):
count = 0
for i in range(len(string) -
len(sub_string) + 1):
if
string[i:i+len(sub_string)] ==
sub_string:
count += 1
return count

if __name__ == '__main__':
string = input().strip()
sub_string = input().strip()

count =
count_substring(string,
sub_string)
print(count)
6. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
7. Learning Outcomes:

 Learn how to traverse a string and extract substrings using slicing in


Python.
 Understand how to check for the presence of a substring at different
positions in the main string.
 Learn how to limit the loop to ensure substring matching without
exceeding the string length.
 Implement logic to count how many times a particular substring appears
in a given string.

8. Time Complexity: O(n*m)

9. Space Complexity: O(1)

You might also like