0% found this document useful (0 votes)
4 views4 pages

String - Practice Questions

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)
4 views4 pages

String - Practice Questions

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/ 4

SIBMT

Subject:-Python Programming

Practice Questions
(String)

Q1. Instagram Bio Character Counter (Counting Characters)

Instagram bios have a limit of 150 characters.​


Write a Python program to:

1.​ Take a bio as input.


2.​ Count the total number of characters in the bio.
3.​ Display the number of remaining characters allowed.

Example Input:

Coding | Traveler | Foodie

Example Output:

Characters used: 26

Remaining characters: 124

Q2. Remove Spaces in a File Name (Using replace())​


When uploading files to a website, spaces in file names need to be replaced with underscores
(_).​
Write a Python program that:

●​ Takes a file name as input.


●​ Replaces all spaces with underscores and displays the new file name.​

Example Input:

Final Project Report.docx

Example Output:

Final_Project_Report.docx
Q3. In a word puzzle game, you are asked to swap every odd-position character with the
next even-position character in a word.

Constraints:

●​ The input word will always have exactly 6 characters.


●​ Do not use loops, if-else statements, or functions.
●​ Use only string indexing and slicing.

Task:

●​ Take a 6-character word as input.


●​ Swap the first and second characters, third and fourth characters, fifth and sixth
characters.
●​ Display the resulting word.

Example Input:
abcdef
Example Output:
badcfe

Q4. Extract Domain Name from Email (Splitting Strings)

An HR department wants to analyze email domains of employees.​


Write a Python program that:

●​ Accepts an email address as input.


●​ Extracts and displays only the domain name.

Example Input:

[email protected]

Example Output:

company.com
Q5. Count Hashtag Occurrences in Social Media Posts (Counting Substrings)

A social media marketing company wants to count how many times a specific hashtag
appears in a campaign post.​
Write a program to:

●​ Accept a text and a hashtag as input.


●​ Display the total count of that hashtag using only count() method.​

Example Input:

Text: #Python is amazing. #AI and #Python will rule the world.

Hashtag: #Python

Example Output:

The hashtag '#Python' appears 2 times.

Q.6 . Create a program that converts all lowercase letters to uppercase and vice versa
using a single built-in method.

Example Input:

PyThOn

Example Output:

pYtHoN

Q.7 A blogging platform needs a word counter for its posts.​


Write a program that:

●​ Accepts a paragraph as input.


●​ Uses split() and len() to display the total number of words

Q.8 Write a program to:Check whether a string starts with "www" and ends with ".com"
using startswith() and endswith().

●​ Display True or False.


Q.9 WAP program that:

●​ Accepts a word as input.


●​ Displays the first character and last character separately using indexing.


Q.10 Write a program to swap the first and last characters of a string using slicing and
concatenation.

Example Input:
coding

Example Output:
godinc

Q.11 A blogging platform wants to count the number of words in a blog post.​
Write a program that:

●​ Accepts a paragraph as input.


●​ Displays the total number of words using split() and len().​

Example Input:

Python is a powerful programming language.

Example Output:

Total words: 6

You might also like