https://www.hackerrank.com/profile/mourad_smail
A collection of Python practice solutions covering core Python concepts and NumPy operations, primarily based on HackerRank challenges.
This repository contains standalone Python scripts, each solving a specific programming challenge. The solutions are organized by topic and demonstrate common Python patterns and NumPy usage.
- Python 3.x
- NumPy (required for all NumPy-related scripts)
Install NumPy with:
pip install numpy| File | Description |
|---|---|
sWAPcASE.py |
Swaps the case of every character in a string (uppercase ↔ lowercase). |
StringFormatting.py |
Prints numbers from 1 to N in decimal, octal, hexadecimal, and binary, right-justified. |
StringSplitAndJoin.py |
Splits a string on spaces and rejoins the tokens with hyphens. |
StringValidators.py |
Checks a string for alphanumeric, alphabetic, digit, lowercase, and uppercase characters. |
FindAString.py |
Counts how many times a substring appears within a string (case-sensitive). |
Mutations.py |
Replaces a character at a given index in a string. |
TextAlignment.py |
Draws an ASCII art "H" pattern using rjust, ljust, and center string methods. |
TextWrap.py |
Wraps a long string to a specified maximum width by inserting newlines. |
WhatSYourName.py |
Accepts a first and last name and prints a personalized greeting. |
DesignerDoorMat.py |
Generates a decorative door-mat pattern with a "WELCOME" centred message. |
| File | Description |
|---|---|
Lists.py |
Processes a sequence of list commands (insert, append, remove, sort, pop, reverse, print). |
Tuples.py |
Creates a tuple from user input and prints its hash value. |
IntroductiontoSets.py |
Computes the average of the unique elements in an array by converting it to a set. |
SymmetricDifference.py |
Placeholder for a symmetric-difference set exercise. |
| File | Description |
|---|---|
Arrays.py |
Converts a space-separated string of numbers into a NumPy float array and reverses it. |
ArrayMathematics.py |
Demonstrates element-wise arithmetic on 2-D NumPy arrays (add, subtract, multiply, floor-divide, mod, power). |
Concatenate.PY |
Vertically stacks multiple NumPy arrays using numpy.vstack(). |
EyeandIdentity.py |
Creates and displays identity matrices using numpy.eye(). |
FloorCeilandRint.py |
Applies numpy.floor(), numpy.ceil(), and numpy.rint() to an array. |
ShapeandReshape.py |
Reads nine numbers and reshapes them into a 3 × 3 NumPy array. |
TransposeandFlatten.py |
Transposes a 2-D NumPy array and then flattens it to 1-D. |
ZerosandOnes.py |
Creates NumPy arrays filled with zeros and ones using numpy.zeros() and numpy.ones(). |
| File | Description |
|---|---|
PrintFunction.py |
Prints integers 1 through N as a single concatenated string without spaces. |
Each script is self-contained and can be run directly from the command line:
python <filename>.pyExample:
python sWAPcASE.pyMany scripts read input interactively. Supply the required values when prompted, or pipe them from a file:
echo "Hello World" | python sWAPcASE.py-
Core Python
- String methods (
split,join,center,ljust,rjust,islower,isupper,isalpha,isdigit,isalnum) - List operations (insert, append, remove, sort, pop, reverse)
- Tuples and hashing
- Sets and set operations
- String formatting (f-strings, format specifiers for octal, hex, binary)
- Text wrapping and alignment
- String methods (
-
NumPy
- Array creation (
numpy.array,numpy.zeros,numpy.ones,numpy.eye) - Array manipulation (
numpy.flip,numpy.vstack,numpy.transpose,.flatten,.reshape) - Element-wise arithmetic (
numpy.add,numpy.subtract,numpy.multiply,numpy.floor_divide,numpy.mod,numpy.power) - Rounding functions (
numpy.floor,numpy.ceil,numpy.rint)
- Array creation (