This notebook contains solutions to various basic Python programming exercises, covering fundamental concepts such as string and list manipulation, conditional statements, and loops.
- String Slicing: (Extracting a portion of a string by specifying start, end, and step indices) used for extracting the first 5 characters from a string.
- List Indexing: (Accessing elements in a list by their numerical position) used for getting the last element of a list.
- String Reversal: (Using slicing with a step of -1 to reverse the order of characters) used for reversing a string.
- List Slicing: (Extracting a sub-list by specifying a range of indices) used for printing elements at even indices from a list of numbers.
- List Modification: (Changing the value of an element at a specific index in a list) used for changing the value of the third element in a list.
- Tuple Access: (Retrieving elements from a tuple using their indices) used for printing the second and last elements of a tuple.
- Type Conversion: (Changing data from one type to another, e.g., tuple to list) used for converting a tuple into a list.
- Conditional Logic (if-elif-else):
(Using
if,elif, andelsestatements to execute code based on multiple conditions) used for checking if a number is positive, negative, or zero. - Conditional Logic (if-else):
(Using
ifandelsestatements to execute code based on a binary condition) used for checking if a number is even or odd. - For Loop: (Iterating over a sequence of elements or a range of numbers) used for printing numbers from 1 to 20.
- While Loop: (Repeatedly executing a block of code as long as a condition is true) used for printing numbers from 10 to 1.
- Loop for Summation: (Using a loop to iteratively add up elements) used for finding the sum of all elements in a list.
- Loop and Condition: (Combining iteration with conditional statements to filter elements) used for printing all numbers divisible by 3 from a list.
- List Element Count:
(Determining the frequency of a specific value in a list, or all values) used for counting how many times a specific value appears in a list (using
count()andcollections.Counter). - Loop for Max Value: (Using a loop and conditional statements to compare and find the largest element) used for finding the largest number in a list.