Day 15 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the factorial of a number using recursion. The goal was to understand how recursion works and how a function can call itself to solve a problem. What the program does: • Takes an integer input from the user • Uses recursion to calculate the factorial • Handles the base case properly • Returns the final factorial value How the logic works: The function factorial(n) is defined If n == 0, the function returns 1 (Base Case) Otherwise, the function returns: n * factorial(n - 1) The function keeps calling itself with smaller values The recursion stops when it reaches the base case The final result is printed Example: Input: 7 Output: 5040 (Because 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040) Key learnings from Day 15: – Understanding recursion and base cases – Learning how function calls are stacked – Breaking a problem into smaller subproblems – Strengthening fundamental algorithm concepts #100DaysOfCode #Day15 #Python #PythonProgramming #Recursion #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
Understanding Recursion with Python Factorial Program
More Relevant Posts
-
📌 Day 49 of #100DaysOfLeetCode 🔹 Problem: Contains Duplicate II (LeetCode 219) 💡 Problem Statement: Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that: nums[i] == nums[j] |i - j| ≤ k In simple words, check if the same number appears again within k distance in the array. ⚙ Approach: Use a HashMap (dictionary) to store the last index of each number. Traverse the array once. If the number already exists in the map: Check the distance between indices. If distance ≤ k, return True. Update the index of the number in the map. ⏱ Complexity: Time Complexity: O(n) Space Complexity: O(n) 🎯 Key Learning: Hashing helps track previously seen elements efficiently and allows solving duplicate problems in linear time instead of nested loops. #LeetCode #DSA #Python #HashMap #CodingChallenge #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 51 of My Python Journey Today I solved Apply Discount to Prices on LeetCode. 🔍 Problem Overview: The problem gives a sentence containing words and prices (values starting with $). The task is to apply a given discount percentage to all valid prices and return the updated sentence. The updated prices must be formatted with exactly two decimal places. 🧠 Approach: • Split the sentence into individual words. • Check whether a word represents a valid price (starts with $ and the remaining characters are digits). • Convert the price to an integer and apply the discount formula. • Format the discounted price to two decimal places and rebuild the sentence. ⚡ Key Learnings: • Practiced string parsing and validation • Improved understanding of formatting numbers in Python • Strengthened problem-solving using conditional logic 📊 Complexity: • Time Complexity: O(n) • Space Complexity: O(n) Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day51 #Python #LeetCode #DataStructures #Algorithms #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 25 – divmod() print(divmod(10, 3)) Use: Quotient & remainder Content: Used divmod() to get quotient and remainder. Useful in math logic. #Python generate like a cartoon style image Image created Generated image Generated image Generated image Share Gulive description to post in. Linked in Here’s a clean LinkedIn-ready description for your post: 🚀 Day 25 of #30DaysOfCode – Learning divmod() in Python Today I explored the divmod() function in Python. print(divmod(10, 3)) 🔹 divmod() returns both the quotient and remainder in a single step. 🔹 Output: (3, 1) 🔹 It combines the functionality of // (floor division) and % (modulus). This function is especially useful in mathematical logic, time calculations, and problem-solving scenarios where both values are needed together. Small functions, big impact! 💡 #Python #PythonBasics #CodingJourney #LearnToCode #Programming #30DaysOfCode
To view or add a comment, sign in
-
-
🚀 Python Learning Journey – Day 12 Today, I learned about Sets in Python and how they store unique values. Here’s what I practiced: ✅ Creating sets ✅ Understanding that sets do not allow duplicates ✅ Adding elements using add() ✅ Removing elements using remove() and discard() ✅ Set operations – union, intersection, difference ✅ Using built-in functions like len(), max(), min(), sum() Sets helped me understand how to work with unique data and perform mathematical operations easily. Learning step by step and improving every day 💪 Consistency continues! #Python #LearningJourney #Beginner #Day12 #Sets #Coding #KeepLearning
To view or add a comment, sign in
-
-
Day 18 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the longest word in a given sentence. The goal was to practice string manipulation and comparison logic. What the program does: • Takes a sentence as input • Splits the sentence into individual words • Compares the length of each word • Stores the longest word found • Prints the final result How the logic works: A sentence is defined as a string The sentence is split into a list of words using .split() A variable longest_word is initialized as an empty string The program loops through each word in the list If the length of the current word is greater than or equal to the stored word, it updates longest_word After the loop ends, the longest word is printed Example: Input sentence: The quick orange fox jumps over the lazy dog Output: Longest word: orange Key learnings from Day 18: – Using .split() for string processing – Comparing string lengths – Iterating through lists efficiently – Strengthening logical thinking skills #100DaysOfCode #Day18 #Python #PythonProgramming #StringManipulation #ProblemSolving #CodingPractice #LogicBuilding #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 42 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the K-th largest element in an array. This is a common problem in coding interviews and helps build understanding of sorting and indexing. What the program does: • Takes an array and a value k as input • Sorts the array in descending order • Returns the k-th largest element • Handles duplicate values correctly How the logic works: • The array is sorted in descending order using sorted() • Since Python uses 0-based indexing,the k-th largest element is at index k-1 • The element at index k-1 is returned as the result Example: Input: Array: [3, 2, 1, 5, 6, 4] k = 2 Output: 5 (2nd largest element) Another example: Input: Array: [3, 2, 3, 1, 2, 4, 5, 5, 6] k = 4 Output: 4 Why this approach works: – Simple and easy to implement – Uses built-in sorting for reliability – Time Complexity: O(n log n) Key learnings from Day 42: – Understanding sorting in descending order – Working with indexing (k-1) – Solving common interview problems – Handling duplicates in arrays #100DaysOfCode #Day42 #Python #PythonProgramming #Arrays #Sorting #Algorithms #DataStructures #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 11/30 – Defining & Calling Functions in Python Today, I learned how to write cleaner and smarter code using functions. Instead of repeating the same logic multiple times, we can define it once and reuse it whenever needed. That’s powerful. 📌 What I practiced: • Defining a function using def • Calling the function • Passing values (arguments) • Returning results Here’s a simple example I built today: . 💡 Key Takeaway: Functions make programs organized, efficient, and professional. Small concept. Big impact. Day 11 complete ✅ #Python #30DaysChallenge #LearningInPublic #ProgrammingJourney #Consistency Aditya ChaturvediJECRC UniversityYash Raj ChoudharyRaj Gehlot
To view or add a comment, sign in
-
-
🚀 30 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐏𝐲𝐭𝐡𝐨𝐧 — 𝐃𝐚𝐲 #20 | 𝐃𝐞𝐞𝐩 𝐃𝐢𝐯𝐞 𝐢𝐧𝐭𝐨 𝐒𝐭𝐫𝐢𝐧𝐠𝐬 & 𝐌𝐞𝐭𝐡𝐨𝐝𝐬 Day 20 was all about going deeper into strings and string methods to build a stronger conceptual understanding. Instead of practicing questions, I focused on understanding how strings work internally and how different methods can be used to manipulate text efficiently. 📌 𝐖𝐡𝐚𝐭 𝐈 𝐂𝐨𝐯𝐞𝐫𝐞𝐝: 🔹 Strengthened my understanding of strings 🔹 𝐬𝐩𝐥𝐢𝐭() — breaking strings into parts 🔹 𝐣𝐨𝐢𝐧() — combining elements into a string 🔹 𝐟𝐢𝐧𝐝() — locating substrings 🔹 𝐫𝐞𝐩𝐥𝐚𝐜𝐞() — modifying text 🔹 Explored multiple other useful 𝐬𝐭𝐫𝐢𝐧𝐠 𝐦𝐞𝐭𝐡𝐨𝐝𝐬 This deeper dive helped me understand how Python handles text data and how these methods are used in real-world scenarios. 💡 𝑲𝒆𝒚 𝑻𝒂𝒌𝒆𝒂𝒘𝒂𝒚 Going deep into concepts builds clarity. When the foundation is strong, applying it becomes much easier and more effective. 𝐃𝐚𝐲 20 𝐜𝐨𝐦𝐩𝐥𝐞𝐭𝐞 ✅ Understanding is getting stronger with every step. 💻✨ #Python #30DayChallenge #Day20 #PythonStrings #StringMethods #LearningJourney #LearnToCode #Programming #TechGrowth #Consistency
To view or add a comment, sign in
-
-
🚀 Python Learning Journey – Revision Day Today, I revised Day 12, Day 13, and Day 14 topics to strengthen my understanding. Here’s what I revised: ✅ Sets (unique elements, set operations like union, intersection, difference) ✅ Matrices (nested lists, accessing elements, basic operations) ✅ Star ⭐ pattern programs (nested loops and logic building) Revision helped me improve my confidence in loops and data structures. Step by step, my problem-solving skills are getting stronger 💪 Consistency is the key to mastery! #Python #LearningJourney #Revision #Sets #Matrix #StarPattern #Coding #KeepLearning
To view or add a comment, sign in
-
👋 Welcome back! 📅 Python Learning – Day 58 Today we explore one of the simplest searching techniques: Linear Search. Linear search checks each element one by one until the target value is found. It may not be the fastest method, but it is easy to understand and works on any list. This is often the first step toward learning more advanced search algorithms. 📘 In this lesson, I’ve explained: 🔍 What linear search is and how it works 📋 How Python checks elements sequentially ⚠️ Common beginner mistakes when implementing search logic Linear search helps you understand the basics of how searching works in programming. Once this is clear, moving to faster algorithms becomes much easier. 🔗 Tutorial link is in the comments. 💬 If you're following this learning series and want to stay connected with more such content, discussions, and updates, you can join our LinkedIn community here: CodePractice Group - (https://lnkd.in/g3xbN4GJ) ⏭️ Tomorrow: Python Binary Search #LinearSearch #SearchAlgorithms #LearnPythonDSA #CodingPractice #AlgorithmBasics #PythonForStudents #TechLearning #DeveloperJourney #pythonlearning #python2026 #codepracticelearning #codepractice #codewithconfidence
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