🚀 Day 11 of Python Learning: Loops and Patterns in Python Today I practiced loops in Python and learned how to create patterns using nested loops. This helps improve logic building and problem-solving skills. 🔹 What are Patterns? Patterns are shapes or number/star designs created using loops. They are great for understanding loop control and nested loops. 🔸 Using For Loop for i in range(5): print("*") 🔸 Star Pattern Example for i in range(1, 6): print("*" * i) Output: * ** 🔸 Number Pattern Example for i in range(1, 6): for j in range(1, i + 1): print(j, end=" ") print() 💡 Key Learning: Nested loops are useful when one loop runs inside another loop, especially for patterns and matrix-style problems. 🧪 Practice Task: ✔ Print reverse star pattern ✔ Print square pattern using stars ✔ Print number triangle pattern ✔ Try same patterns using while loop 🎯 Interview Question: What is a nested loop in Python? Answer: A nested loop is a loop inside another loop. It is used when repeated iterations are needed within each cycle of the outer loop. 📌 Day 11 completed — logic building step by step! #Python #Learning #CodingJourney #Day11 #Programming #SDET #100DaysOfCode Masai #dailyleaning #masaiverse
Python Loops and Patterns for Logic Building
More Relevant Posts
-
🚀 Day 6 of Python Learning: Functions in Python Today I learned how to organize and reuse code using functions — a key concept for writing clean and efficient programs. 🔹 What is a Function? A function is a block of code that performs a specific task and can be reused whenever needed. 🔸 Creating a Function Example: def greet(): print("Hello, welcome to Python!") greet() 🔸 Function with Parameters Example: def greet(name): print("Hello", name) greet("Rohit") 🔸 Function with Return Value Example: def add(a, b): return a + b result = add(5, 3) print(result) 💡 Key Learning: Functions help reduce code repetition and make programs more structured and readable. 🧪 Practice Task: Create a function to check even or odd Create a function to add two numbers Create a function to find the square of a number 🎯 Interview Question: What is the difference between return and print in Python? Answer: "print displays output on the screen, while return sends the value back to the function caller." #Python #Learning #CodingJourney #Day6 #Programming #SDET Masai #dailylearning #masaiverse #SDET
To view or add a comment, sign in
-
-
🚀 Day 7 of Python Learning: Lists in Python Today I learned about Lists — one of the most useful data structures in Python for storing multiple values in a single variable. 🔹 What is a List? A list is a collection of items stored in a single variable. It can store different data types like numbers, strings, etc. 🔸 Creating a List my_list = [1, 2, 3, 4, 5] 🔸 Accessing Elements print(my_list[0]) # First element print(my_list[-1]) # Last element 🔸 Updating List my_list[1] = 10 🔸 Adding Elements my_list.append(6) 🔸 Removing Elements my_list.remove(3) 💡 Key Learning: Lists are mutable, which means we can change their values after creation. 🧪 Practice Task: ✔ Create a list of 5 numbers ✔ Add a new number ✔ Remove one number ✔ Print all elements using a loop 🎯 Interview Question: What is the difference between list and tuple in Python? Answer: "List is mutable (can be changed), while tuple is immutable (cannot be changed)." 📌 Day 7 done — building consistency step by step! #Python #Learning #CodingJourney #Day7 #Programming #SDET #100DaysOfCode Masai #dailylearning, #masaiverse
To view or add a comment, sign in
-
-
Day 11 of my Python learning journey Today I tried solving the Two Sum problem using the Two Pointer technique. Before this, I was only solving Two Sum using a dictionary. But today I learned another approach that works when the array is sorted. Problem: Two Sum (Two Pointer Approach) Given a sorted array and a target value, find two numbers whose sum equals the target. Example: nums = [1, 2, 4, 6, 10] target = 8 Output: [2, 6] Because 2 + 6 = 8. What is the Two Pointer technique? Two pointers means using two positions in the array: one pointer starts from the left side one pointer starts from the right side Then we move them based on the sum. How it works: • If the sum is too small, move the left pointer forward • If the sum is too large, move the right pointer backward • If the sum equals the target, we found the answer Code: nums = [1, 2, 4, 6, 10] target = 8 left = 0 right = len(nums) - 1 while left < right: s = nums[left] + nums[right] if s == target: print(nums[left], nums[right]) break elif s < target: left += 1 else: right -= 1 Problems I faced while coding this: At first I did not understand why the array needs to be sorted. I was confused about when to move the left pointer and when to move the right pointer. I also tried using this method on an unsorted array and it did not work. What I finally understood: The Two Pointer technique works well when the array is sorted because it lets us adjust the sum efficiently without checking every pair. This reduces the time complexity compared to nested loops. Question: Would this approach still work if the array was not sorted? #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Day 13 of Python Learning: Exception Handling in Python Today I learned how to handle errors in Python using exception handling. This helps programs run smoothly even when unexpected issues occur. 🔹 What is Exception Handling? Exception handling is used to catch errors and prevent the program from crashing. 🔸 Basic Example try: num = 10 / 0 except: print("Error occurred") 🔸 Handling Specific Error try: number = int("abc") except ValueError: print("Invalid input") 🔸 Using Finally Block try: print("Start") except: print("Error") finally: print("This always runs") 🔸 Using Else Block try: print(10 / 2) except: print("Error") else: print("No error found") 💡 Key Learning: Using try-except makes programs more reliable and user-friendly. 🧪 Practice Task: ✔ Handle divide by zero error ✔ Handle invalid number input ✔ Use finally block in one program ✔ Create a safe calculator using try-except 🎯 Interview Question: What is the purpose of finally block in Python? Answer: The finally block always executes whether an error occurs or not. It is commonly used for cleanup tasks like closing files or database connections. 📌 Day 13 completed — learning how professionals handle errors! #Python #Learning #CodingJourney #Day13 #Programming #SDET #100DaysOfCode Masai #masaiverse #dailylearning
To view or add a comment, sign in
-
Python Learning Journey - Deep Dive into Core Concepts Continuing my Python journey, today I explored some powerful and practical concepts that strengthen problem-solving skills: ◆ Loops in Python - for loop & while loop ◆ Strings in Python Finding length using len() Accessing characters using index & slicing Exploring string methods & formatting ◆ Hands-on Practice Program to accept a string & find its reverse ◆ List Data Structure : Built-in functions: len(), index(), append(), insert(), remove(), clear(), sort() Understanding id() function Aliasing vs Cloning of lists Cloning using slicing & copy() ◆ Operators on Lists Multiplication & Concatenation Relational & Membership operators Advanced Concepts Nested Lists List Comprehension Complete List Data Structure Summary Learning Python is all about consistency, practice, and building logic step by step. #Globalquesttechnologies #GR Narendra Reddy #Python #Coding Journey #Learning Python #Programming #Developers #100DaysOfCode #TechSkills #PythonBasics
To view or add a comment, sign in
-
-
Day 18 of my Python learning journey Today I tried another good problem based on the Two Pointer technique. Problem: Merge Sorted Array Given two sorted arrays, merge them into one sorted array. Example: arr1 = [1, 3, 5] arr2 = [2, 4, 6] Output: [1, 2, 3, 4, 5, 6] What I understood: Since both arrays are already sorted, we do not need to sort again. We can compare elements from both arrays and place the smaller one first. Better approach (Two Pointer): One pointer for arr1 One pointer for arr2 Compare both values Add the smaller value to the result Code I wrote: arr1 = [1, 3, 5] arr2 = [2, 4, 6] i = 0 j = 0 result = [] while i < len(arr1) and j < len(arr2): if arr1[i] < arr2[j]: result.append(arr1[i]) i += 1 else: result.append(arr2[j]) j += 1 while i < len(arr1): result.append(arr1[i]) i += 1 while j < len(arr2): result.append(arr2[j]) j += 1 print(result) Problems I faced while coding this: At first I thought I had to combine both arrays and then sort them. I was confused about why two pointers are enough. I also forgot to handle the remaining elements after one array finishes. What I finally understood: Because both arrays are sorted, we can merge them in one pass. This saves extra sorting work and makes the solution efficient. Time and Space Complexity: Time Complexity: O(n + m) Space Complexity: O(n + m) Question: What will be the output for: arr1 = [1, 2, 7] arr2 = [3, 4] Today’s realization: Sometimes the best solution is not creating something new, but combining what is already ordered. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Day 5 of Python Learning: Loops in Python Today I learned how to repeat tasks using loops — one of the most powerful concepts in programming. 🔹 What are Loops? Loops help us execute a block of code multiple times without writing it again and again. 🔸 For Loop Used when the number of iterations is known. Example: for i in range(1, 6): print(i) 🔸 While Loop Used when the number of iterations is not known. Example: i = 1 while i <= 5: print(i) i += 1 🔸 Loop Control Statements ✔ break → Stops the loop completely ✔ continue → Skips current iteration ✔ pass → Does nothing (placeholder) 💡 Key Learning: Use "for loop" for fixed iterations and "while loop" for condition-based execution. 🧪 Practice Task: Print numbers from 1 to 10 using a loop Find factorial of a number 🎯 Interview Question: What is the difference between for loop and while loop? Answer: "For loop is used when the number of iterations is known, while loop is used when the condition decides the execution." #Python #Learning #CodingJourney #Day5 #Programming #SDET Masai #dailylearning #masaiverse #SDET
To view or add a comment, sign in
-
-
Day 17 of my Python learning journey Today I tried another interesting problem using the Two Pointer technique. Problem: Valid Palindrome Given a string, check if it can become a palindrome after removing at most one character. Example: s = "abca" Output: True Because removing 'c' makes it "aba" which is a palindrome. What I understood: We need to check if the string is almost a palindrome, allowing one mistake. Better approach (Two Pointer): Start one pointer from left Start one pointer from right If characters match → move both pointers If mismatch → try skipping one character (either left or right) Code I wrote: def is_palindrome(s, left, right): while left < right: if s[left] != s[right]: return False left += 1 right -= 1 return True s = "abca" left = 0 right = len(s) - 1 while left < right: if s[left] != s[right]: if is_palindrome(s, left + 1, right) or is_palindrome(s, left, right - 1): print(True) else: print(False) break left += 1 right -= 1 else: print(True) Problems I faced while coding this: At first I tried removing every character and checking, which was inefficient. I was confused about which character to remove when mismatch happens. Writing a helper function for checking palindrome took some time to understand. What I finally understood: At the first mismatch, we only need to try two cases: skip left character skip right character If any one works, the string is valid. Time and Space Complexity: Time Complexity: O(n) Space Complexity: O(1) Question: What will be the output for: s = "abc" Today’s realization: Sometimes solving a problem is about allowing one controlled mistake. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Python Learning Journey – Day 5: Lists in Python 🐍 Continuing my Python journey, today I learned about Lists, one of the most useful data structures in Python 🔥 📌 Key Takeaways: ✔️ Lists can store multiple values of different data types ✔️ Lists support indexing & slicing just like strings ✔️ Lists are mutable (we can change them anytime) 💻 Basic Example: l1 = [7, 9, "siddu"] print(l1[0]) # 7 print(l1[1]) # 9 📌 List Methods I Practiced: ✔️ sort() → Sorts the list ✔️ reverse() → Reverses the list ✔️ append() → Adds element at the end ✔️ insert() → Adds element at a specific index ✔️ pop() → Removes element using index ✔️ remove() → Removes a specific value 💻 Example: l1 = [1, 8, 7, 2, 21, 15] l1.sort() l1.append(8) l1.insert(3, 8) l1.pop(2) l1.remove(21) print(l1) ✨ Slowly building my foundation in Python step by step. Consistency is key! #Day5 #PythonLearning #CodingJourney #LearnPython #ProgrammingBasics #FutureBusinessAnalys
To view or add a comment, sign in
-
🚀 Python Basics to Advanced Learning Series – Day 12 Today’s session was focused on the Set data structure in Python. It helped me understand how to store and manage unique values efficiently. What I learned today: • What is a Set and how it works in Python • How to create a set using {} and set() function • How to create an empty set using set() (since {} creates a dictionary) • Understanding that sets store unique and unordered elements • Learning important built-in methods of sets: add() → to add a single element update() → to add multiple elements copy() → to create a duplicate set pop() → to remove a random element remove() → to remove a specific element (error if not found) discard() → to remove element without error • Understanding the difference between pop(), remove(), and discard() • Practiced examples to clearly understand how sets behave This session helped me understand how sets are useful when working with unique data and how different methods behave in real scenarios. I’m learning step by step as part of my Python Basics to Advanced Learning Journey at Global Quest Technologies, and I’m improving my concepts day by day. Excited to continue learning and building strong fundamentals 🚀 #Python #PythonProgramming #LearningJourney #Coding #DataStructures #Sets #ProblemSolving #SoftwareDevelopment #TechLearning #Developers #GlobalQuestTechnologies
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development