0% found this document useful (0 votes)
16 views

python Assignment_4

Python Assignment 4
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)
16 views

python Assignment_4

Python Assignment 4
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/ 2

Assignment-IV

(Mutable and Immutable Objects)

CSE 2197: Python Programming for IOT


Session: Sep 2024 to Jan 2025
Branch: CSE(IOT)
Course Outcomes: CO1

Learning Levels: Remembering (L1), Understanding (L2), Application (L3), Analysis (L4), Evaluation (L5),
and Creation (L6)

Q no. Questions Learning


Levels

Write a function reverse_string(s) that takes a string s as input and returns the
reversed string.
Q1. L2, L3
Example: Input: "hello" Output: "olleh"
Write a function count_vowels(s) that takes a string s as input and returns the number
of vowels in the string.
Q2. L2, L3
Example: Input: "hello world" Output: 3
Write a function is_palindrome(s) that takes a string s as input and returns True if the
string is a palindrome, and False otherwise.
Q3. L2, L3
Example: Input: "madam" Output: True
Write a function compress_string(s) that takes a string s as input and returns the
compressed string. The compression should be done by replacing consecutive
Q4. repeated characters with a single character. L4, L6

Example: Input: "aaabbbccc" Output: "abc"


Write a function caesar_cipher(s, shift) that takes a string s and an integer shift as
input and returns the encrypted string using the Caesar cipher algorithm.
Q5. L4, L6
Example: Input: "hello", 3 Output: "khoor"
Write a function is_anagram(s1, s2) that takes two strings s1 and s2 as input and
returns True if the strings are anagrams, and False otherwise.
Q6. L4, L6
Example: Input: "listen", "silent" Output: True
Write a function permute_string(s) that takes a string s as input and returns all
possible permutations of the string.
Q7. L4, L6
Example: Input: "abc" Output: "abc", "acb", "bac", "bca", "cab", "cba"
Write a function longest_common_substring(s1, s2) that takes two strings s1 and s2 as
input and returns the longest common substring.
Q8. L4, L6
Example: Input: "abcdef", "zbcdfg" Output: "bcd"
Write a function string_matching(s, pattern) that takes a string s and a pattern pattern
as input and returns the starting index of the pattern in the string, or -1 if the pattern is
Q9. not found. L4, L6

Example: Input: "hello world", "world" Output: 6


Write a function word_frequency(text) that takes a string text as input and returns
words and their frequencies.
Q10. L4, L6
Example: Input: "This is a test. This test is fun." Output: 'this': 2, 'is': 2, 'a': 1, 'test':
2, 'fun': 1
Write a function reverse_sentence(sentence) that takes a string sentence as input and
returns the sentence with words in reverse order.
Q11. L4, L6
Example: Input: "This is a test sentence" Output: “sentence test a is This”
Write a function char_frequency(text) that takes a string text as input and returns
character and their frequencies.
Q12. L4, L6
Example: Input: "Hello, World!" Output: 'H': 1, 'e': 1, 'l': 3, 'o': 2, ',': 1, ' ': 1, 'W': 1,
'r': 1, 'd': 1, '!': 1
Write a function word_count(text) that takes a string text as input and returns the word
count without using str.split() function.
Q13. L4, L6
Example: Input: "This is a test sentence" Output: 5
Write a function remove_duplicates(text) that takes a string text as input and returns
the text with duplicate words removed.
Q14. L4, L6
Example: Input: "This is a test. This test is fun." Output: “This is a test fun”
Write a function is_valid_email(s) that takes a string s as input and returns True if the
Q15. L4, L6
string is a valid email address, and False otherwise.

END

You might also like