This repository contains six small, focused Python programs completed for the Week 1 assignment. Each script introduces a fundamental concept: type conversion and formatting, string parsing, indexing and slicing, conditional logic, frequency counting, and character classification.
- Purpose: Practice core Python concepts via small, interactive scripts.
- Scope: Six standalone programs, each prompting for input and printing results.
- Platform: macOS or any system with a modern Python interpreter.
assignment_week_1_q1.py— Convert a decimal number to int and string; format output.assignment_week_1_q2.py— Extract uppercase initials from a provided full name.assignment_week_1_q3.py— Slice a given word from a specified starting index.assignment_week_1_q4.py— Assess password strength using simple rules.assignment_week_1_q5.py— Count frequency of alphabetic characters in a string.assignment_week_1_q6.py— Count vowels and consonants in a string.
- Python
3.8+recommended (any modern 3.x works) - Terminal access to run scripts (
python3on macOS)
- Open Terminal and navigate to the project folder:
cd "/Users/prashantkoirala/Desktop/Python Module Assignemnt"
- Run a script with:
Replace
python3 assignment_week_1_qX.py
Xwith1–6depending on the question.
- Prompts for a decimal number, converts it to
intandstr, and prints the original float with two decimal places. - Concepts: type casting (
int,str), string formatting (format/{:.2f}). - Example:
Please, enter a decimal number: 12.345 Original float: 12.35 Converted to integer: 12 Converted to string: "12.345"
- Trims whitespace, splits the full name by spaces, and prints uppercase initials from the first and last parts.
- Concepts:
strip,split, indexing, string methods. - Notes: For a single-name input, both initials derive from the same word (
A.A). - Example:
Please, enter your full name: Ada Lovelace Your initials are: A.L
- Prompts for a word and a starting index, then prints the substring from that index to the end.
- Concepts: input parsing,
intconversion, slicing (word[index:]). - Edge behavior: Negative indices are allowed (Pythonic slicing). Out-of-range indices yield an empty string without error.
- Example:
Please, enter a word: python Enter starting index: 2 Substring from index 2 : "thon"
- Evaluates password strength using simple heuristics:
- Weak: length
< 6or only letters (isalpha). - Moderate: length
>= 6and alphanumeric (isalnum). - Strong: length
>= 8and contains at least one of@#$%&. - Else: Moderate.
- Weak: length
- Concepts: conditionals (
if/elif/else), length checks, membership tests. - Notes: The strong rule is limited to the special set
@#$%&. Other symbols are treated as non-strong unless included in that set. - Example:
Please, enter your password: Passw0rd@ Password strength: Strong
- Lowercases the text and counts occurrences of alphabetic characters (
a–z). Non-letters are ignored. - Concepts: dictionaries, iteration,
isalpha, case normalization. - Output order follows first occurrence insertion order of characters.
- Example:
Please, enter a string: Hello, World! h → 1 e → 1 l → 3 o → 2 w → 1 r → 1 d → 1
- Lowercases input and counts vowels (
aeiou) vs consonants; non-alphabetic characters are ignored. - Concepts: classification, membership tests, conditional increments.
- Example:
Please, enter a string: Hello, World! Vowels: 3 Consonants: 7
- Provide valid inputs to avoid
ValueError(e.g., enter an integer for index in Q3). - Try edge cases:
- Q2: Single-word name, multiple middle names.
- Q3: Negative and very large indices.
- Q4: Short passwords, all letters, all digits, and with symbols outside
@#$%&. - Q5: Mixed punctuation and spaces.
- Q6: Strings with no letters.
- Completed as part of the Python Module Week 1 assignment under Professor Anudit Pokhrel.