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

Python Practice Questions

The document is a Python programming practice workbook focused on core fundamentals such as strings, slicing, loops, and conditions. It includes a series of challenges ranging from basic to advanced, requiring users to write scripts that manipulate strings and implement logical conditions. The workbook emphasizes writing clean code and avoiding advanced built-in methods to enhance learning.
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)
3 views3 pages

Python Practice Questions

The document is a Python programming practice workbook focused on core fundamentals such as strings, slicing, loops, and conditions. It includes a series of challenges ranging from basic to advanced, requiring users to write scripts that manipulate strings and implement logical conditions. The workbook emphasizes writing clean code and avoiding advanced built-in methods to enhance learning.
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

Python Programming Practice Workbook

Core Fundamentals: Strings, Slicing, Loops, Conditions & Len Function

Workbook Guidelines:
• Focus on writing clean, readable code with appropriate variable names.
• All problems are designed to test structural execution combining logical loops and text manipulations.
• Try to solve these without using advanced built-in string methods like .replace() or .reverse() to
maximize learning value.

Section 1: Basic & Intermediate Challenges

Question 1: The Domain Extractor

Write a program that takes an email address string as input. Using standard indexing or the len()
function, split the string to extract and print only the username (everything before '@') and the domain
name (everything after '@').

Concepts: Strings, Slicing, Len, Conditions

Input: "student2026@[Link]"
Output:
Username: student2026
Domain: [Link]

Question 2: Dynamic Palindrome Verification

Create a script that prompts the user for a word. The script must check if the word is a palindrome
(reads the same forward and backward) using string slicing. Additionally, if the string length is odd, print
the exact middle character; otherwise, print a message stating the length is even.

Concepts: Strings, Slicing, Len, Conditions

Input: "radar"
Output:
Is Palindrome: True
Middle Character: d

Python Foundations Challenge Page 1 of 3


Question 3: Selective Vowel Masking

Write a program that iterates through a given sentence using a loop. Construct a new string where all
vowels (a, e, i, o, u) are replaced with an asterisk (*), but only if the vowel appears at an even index
position in the string. Keep all other characters unchanged.

Concepts: Strings, Loops, Conditions, Len

Input: "python programming"


Output: "pyth*n pr*gr*mming"

Question 4: Alternate Character Fabricator

Given a string input, utilize string slicing steps to generate two new strings: one containing all characters
at odd indices and another containing characters at even indices. Compare their lengths and display
which slice generated a longer string.

Concepts: Strings, Slicing, Len, Conditions

Input: "CodeChallenge"
Output:
Even Slice: CdCalleng
Odd Slice: oehlne
Result: Even slice is longer

Section 2: Advanced Construct Challenges

Question 5: Secure Password Truncator & Validator

Design a script that takes a password string. First, verify if the length of the password is at least 8
characters long. If it is valid, use slicing to obscure it by taking only the first 3 characters and appending
"..." followed by the total length of the original password. If it is less than 8 characters, flag it as unsafe.

Concepts: Strings, Slicing, Len, Conditions

Input: "SuperSecret123"
Output: "Sup...14"

Python Foundations Challenge Page 2 of 3


Question 6: Frame & Reverse Loop Manipulation

Accept a sentence from the user. Using a loop that counts backwards (from the last index down to 0
determined by len()), build a completely reversed version of the sentence. However, if the word "stop"
appears anywhere inside the sentence, break out of the loop immediately.

Concepts: Strings, Loops, Len, Conditions

Input: "we start now"


Output: "won trats ew"

Question 7: Balanced Boundary Verification

Write a program that accepts a word and inspects its boundaries. Use slicing to extract a substring of
the first 3 characters and another substring of the last 3 characters. Utilize conditional statements to
check if these two sub-segments are identical. Print the outcome along with the total character count.

Concepts: Strings, Slicing, Len, Conditions

Input: "testmaniatest"
Output: "Match Found! Total length: 13"

Python Foundations Challenge Page 3 of 3

You might also like