The Dynamic Devs team is thrilled to bring you Week 4 of the Steemit Learning Challenge Season 21, dedicated to string manipulation and operations in Python. This week’s competition dives deeper into Python’s extensive capabilities for handling strings, incorporating advanced functions and operators, and culminates in building practical applications using Qt Designer. Our goal is to strengthen your grasp of text processing while showcasing your skills in crafting interactive Python projects.
In Python, a string is a sequence of characters enclosed within quotes (single '
, double "
, or triple """
). Strings are immutable, meaning you cannot change their content directly once created. They are a fundamental data type used in almost every Python program.
Examples:
A string in Python is a sequence of characters enclosed in quotes. It is widely used for storing and manipulating text data, making it a foundational data type in programming. Mastering string manipulation allows developers to handle tasks like data parsing, text formatting, and user input processing efficiently.
Key characteristics of strings in Python:
Strings are essential in applications such as:
Qt Designer allows you to create user-friendly graphical interfaces that connect with Python scripts. Using Qt Designer in this challenge will enhance your skills in combining backend programming (string manipulation) with frontend design, making your applications more practical and visually appealing.
Each character in a string can be accessed using its index, starting from 0
for the first character. Negative indices can be used to access characters from the end.
Extract a portion of the string using slicing (start:end excluded
).
Example:
Python offers powerful functions to manipulate strings:
.find(substring)
: Finds the first occurrence of a substring..count(substring)
: Counts how many times a substring appears.Example:
.upper()
, .lower()
: Convert case..title()
: Capitalize the first letter of each word..swapcase()
: Swap uppercase to lowercase and vice versa.Example:
.split()
: Splits a string into a list based on a delimiter..join(iterable)
: Joins elements of a list into a string.Example:
.strip(chars)
: Removes specified characters from both ends..lstrip(chars)
and .rstrip(chars)
: Remove characters from the left or right.Example:
Python provides operators for efficient string handling:
+
for concatenation*
for repetition
in
for membership testingExamples:
Task1 (2pts)
Create a Python program with a graphical user interface (GUI) using PyQt5 to find the intersection of characters between two strings. The program must validate that both strings contain only lowercase alphabetic characters (a-z) and are between 1 and 30 characters long. If either string is invalid, an error message is displayed.
The GUI includes input fields for both strings, a button to process and find the intersection, and another button to clear all inputs and results. The intersection is computed by identifying characters present in both strings without duplicates, respecting their first appearance order in the first string.
Use PyQt5 for the interface, including two buttons ("Find Intersection" and "Clear"), two input fields, and a label to display results or error messages.
Task2(2pts)
Create a Python program with a graphical user interface (GUI) using PyQt5 to reverse the characters of each word in a string, preserving the word order. The program validates that the input string contains only lowercase alphabetic characters and spaces, is between 1 and 50 characters long, and does not start or end with a space. Consecutive spaces are not allowed between words.
The GUI includes an input field for the string, a button to process the input and display the reversed words, and a button to clear the input and result fields. The main functionality involves reversing the characters of each word while keeping the original word order intact, providing immediate feedback to the user.
Task3(2pts)
Create a Python program with a graphical user interface (GUI) using PyQt5 to encrypt a string by combining Caesar cipher rotation (by 13 positions) and reversing the rotated string. The program validates that the input string contains only lowercase alphabetic characters (a-z
) and has a length between 1 and 9. If the input is invalid, an appropriate error message is displayed.
The GUI includes an input field for the string, a button to process the input and display the encrypted result, and another button to clear all inputs and results. The encryption is performed in two steps: first, each character is shifted by 13 positions in the alphabet (modulo 26), and then the resulting string is reversed. Immediate feedback is provided in the result display.
Task4 (2pts)
Create a Python program with a graphical user interface (GUI) using PyQt5 to verify whether two positive integers form a "perfect succession." A perfect succession is defined as a series of digits from the two numbers that, when combined and sorted, form a sequence where each digit increments by one. The program validates that the inputs are positive integers. If either input is invalid, an appropriate error message is displayed.
The GUI includes two input fields for the integers, a button to process the inputs and check the succession, and another button to clear all inputs and results. The program combines the two numbers into a single string, sorts the digits, and checks if they form a consecutive sequence. The result displays either confirmation of a perfect succession with the sorted sequence or a message indicating that the numbers do not form a perfect succession.
Task5 (2pts)
Create a Python program with a graphical user interface (GUI) using PyQt5 to process a sentence by sorting its words based on their lengths in ascending order. The program validates that the input string adheres to the following rules: it must start with a letter, end with a period, have a maximum of 15 words, and contain only single spaces between words. If the input fails any of these validations, an appropriate error message is displayed.
The GUI includes an input field for entering the sentence, a button to sort the words by length, and another button to clear the input and result fields. The program splits the input string into words, sorts them by length using an auxiliary array, and reconstructs the sentence with the sorted words. The result is displayed, preserving a proper sentence structure but sorted from the shortest to the longest word.
At the end of the week:
We encourage you to showcase your creativity and technical skills by exploring Python's advanced string manipulation features and combining them with interactive GUIs. Happy coding!
Best Regards,
Dynamic Devs Team