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

Python Strings Assignment

This document is a Python Strings Assignment consisting of 25 questions categorized into beginner, intermediate, and advanced levels. It covers various string manipulation tasks such as counting characters, checking palindromes, and implementing a Caesar Cipher. Additionally, there are bonus challenges and practice on built-in string methods, along with instructions for writing clean code and submitting solutions.

Uploaded by

kumarshivankar73
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)
3 views5 pages

Python Strings Assignment

This document is a Python Strings Assignment consisting of 25 questions categorized into beginner, intermediate, and advanced levels. It covers various string manipulation tasks such as counting characters, checking palindromes, and implementing a Caesar Cipher. Additionally, there are bonus challenges and practice on built-in string methods, along with instructions for writing clean code and submitting solutions.

Uploaded by

kumarshivankar73
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

Python Strings Assignment

Beginner to Advanced (25 Questions)


Student Name: ______________________
Class: ______________________
Date: ______________________

Python Strings Assignment


Beginner Level (Questions 1–10)
1.
Create a string containing your full name and print it.

2.
Write a program to find the length of a string.

3.
Print the first character and the last character of a string.

4.
Write a program to print each character of a string using indexing.

5.
Use positive and negative indexing to access different characters of a string.

6.
Write a program to print the first five characters of a string using slicing.

7.
Print the last five characters of a string using negative slicing.

8.
Write a program to convert a string to:
 Uppercase
 Lowercase
 Title Case
 Capitalize Case
9.
Write a program to count the number of vowels in a string.

10.
Write a program to check whether a given character exists in a string.

Intermediate Level (Questions 11–18)


11.
Write a program to count the number of words in a sentence.

12.
Write a program to reverse a string using slicing.

13.
Write a program to check whether a string is a palindrome.

14.
Write a program to count the frequency of each character in a string.

15.
Write a program to replace all spaces in a string with underscores (_).

16.
Write a program to remove all whitespace from a string.

17.
Write a program to check whether two strings are anagrams of each other.

18.
Write a program to find the first occurrence and last occurrence of a given
character in a string.
Advanced Level (Questions 19–25)
19.
Write a program to count:
 Uppercase letters
 Lowercase letters
 Digits
 Special characters
20.
Write a program to remove duplicate characters from a string while
maintaining the original order.

21.
Write a program to find the longest word in a sentence.

22.
Write a program to compress a string by counting consecutive repeated
characters. Example:
Input: aaabbccccd
Output: a3b2c4d1

23.
Write a program to check whether two strings are rotations of each other.
Example:
Input:
String 1: ABCD
String 2: CDAB

Output:
Yes

24.
Write a program to encrypt and decrypt a message using a simple Caesar
Cipher.
 Take the shift value as input from the user.
 Display both the encrypted and decrypted text.
25.
Create a menu-driven String Utility Program that allows the user to
perform the following operations:
 Find the length of a string
 Convert to uppercase
 Convert to lowercase
 Reverse the string
 Check palindrome
 Count vowels
 Replace a word
 Search a substring
 Exit

Bonus Challenge (Optional)


1.
Check whether a string contains only alphabets.

2.
Find the most frequently occurring character in a string.

3.
Write a program to remove all punctuation marks from a sentence.

4.
Create a password validator that checks whether a password contains:
 At least 8 characters
 One uppercase letter
 One lowercase letter
 One digit
 One special character
5.
Write a program that checks whether two sentences are identical after
ignoring spaces, punctuation, and letter case.
Practice on Built-in String Methods
Write a Python program demonstrating the use of the following methods:
1. upper()
2. lower()
3. title()
4. capitalize()
5. swapcase()
6. strip()
7. lstrip()
8. rstrip()
9. replace()
10. find()
11. rfind()
12. index()
13. count()
14. startswith()
15. endswith()
16. split()
17. join()
18. isalpha()
19. isdigit()
20. isalnum()
21. isspace()
22. islower()
23. isupper()
24. istitle()
25. casefold()

Instructions
 Write clean and properly indented Python code.
 Use meaningful variable names.
 Add comments where necessary.
 Test your program with different inputs.
 Submit all solutions in a single Python file ( strings_assignment.py).

You might also like