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
Python divmod() Function: Quotient & Remainder
More Relevant Posts
-
🚀 Day 4 – DSA Daily Series Move Zeroes (LeetCode 283) using Python. 🧠 Problem Given an integer array nums, move all 0’s to the end of the array while maintaining the relative order of the non-zero elements. Important constraints: • The operation must be done in-place • No extra array should be created Example: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] 💡 Approach Used the Two Pointer technique. • Maintain a pointer k to track the position for the next non-zero element • Traverse the array using index i • Whenever a non-zero element is found, swap it with the element at position k • Increment k This ensures: • Non-zero elements move to the front • Zeros automatically shift toward the end ⏱ Complexity Time Complexity: O(n) – single pass through the array Space Complexity: O(1) – in-place modification 🔎 Key Learning This problem helps strengthen: • Two Pointer pattern • In-place array manipulation • Maintaining relative order while rearranging elements Consistency is key when practicing DSA — solving one problem at a time. 🚀 #DSA #LeetCode #Python #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Tried solving a sliding window problem today in Python Found the maximum average subarray of size k without recalculating everything again and again — just shifting the window and updating the sum. Simple logic, but really powerful for optimization! nums = [1,12,-5,-6,50,3] n = len(nums) k = 4 max_avrg = float("-inf") window = sum(nums[:k]) max_avrg = window/k for j in range (k,n): window = window - nums[j-k] + nums[j] if max_avrg < window/k: max_avrg = window/k print(max_avrg) Learning DSA step by step #Python #DSA #SlidingWindow
To view or add a comment, sign in
-
If your code is getting longer… ................................................................. you’re probably doing something wrong. That hit me hard while doing today’s Python MahaRevision 👇 📘 Chapter 8: Functions & Recursion Instead of writing the same logic again and again, I learned how to simplify everything: → Functions: write once, reuse anytime → Parameters & return values → Breaking big problems into smaller pieces → Recursion: when a function calls itself Practice set done: Built functions for repeated tasks, passed inputs, returned outputs, and tried recursion problems (confusing at first, but interesting). Not gonna lie—recursion felt weird in the beginning. But it also showed me a different way of thinking. The real shift? It’s not about writing more code… it’s about writing smarter code. Slowly starting to see the bigger picture. #Python #LearningInPublic #CodingJourney #Programming #100DaysOfCode
To view or add a comment, sign in
-
⚠️ Strings look simple… until they aren’t. Back with my Python MahaRevision — and today’s focus was on: 📘 Chapter 3: Strings From basic text handling to powerful operations, this chapter showed me that strings are way more than just “text” in Python 👇 🔹 String slicing & indexing 🔹 String functions & methods 🔹 Escape sequences 🔹 Immutability of strings 🧠 Practice Set Completed! Worked on problems like: • Manipulating and slicing strings • Finding and replacing words • Formatting outputs • Real-world text-based logic 💡 Biggest takeaway: Small concepts like slicing and methods can solve surprisingly complex problems when used right. Learning in public. Staying consistent. Improving daily 🚀 #Python #CodingJourney #LearningInPublic #Programming #Tech #100DaysOfCode
To view or add a comment, sign in
-
Python Clarity Series – Episode 19 Topic: map() vs Loop 📌 Two ways to apply a function to a list. Traditional loop: nums = [1,2,3,4] squares = [] for i in nums: squares.append(i*i) Pythonic way: nums = [1,2,3,4] squares = list(map(lambda x: x*x, nums)) 👉 map() applies a function to every element. Result: [1, 4, 9, 16] 💡 Clarity Thought: Loop → easy to understand map() → shorter and functional style Both are correct. Python gives multiple ways to solve problems. Understanding both improves coding flexibility. #PythonLearning #CodingEfficiency #FutureDevelopers
To view or add a comment, sign in
-
-
🧠 Python Concept: List Comprehension Write powerful loops in one clean line. ❌ Traditional Way squares = [] for i in range(5): squares.append(i * i) print(squares) Output [0, 1, 4, 9, 16] ✅ Pythonic Way squares = [i * i for i in range(5)] print(squares) Same result, less code. ⚡ With Condition even_squares = [i * i for i in range(10) if i % 2 == 0] print(even_squares) Output [0, 4, 16, 36, 64] 🧒 Simple Explanation Imagine telling a robot: 👉 “Give me squares of numbers from 0–4.” 👉 Instead of repeating instructions, you give one rule. 👉 That rule = list comprehension. 💡 Why This Matters ✔ Shorter code ✔ Faster execution ✔ More readable loops ✔ Very Pythonic 🐍 Python often replaces multiple lines with a single elegant expression 🐍 List comprehensions are one of the most powerful examples of that philosophy. #Python #PythonTips #PythonTricks #AdvancedPython #List #ListComprehension #Tech #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
🔍 Day 36 of My Problem Solving Journey Today I explored one of the most important concepts in strings — Searching & Finding. In Python, we often use methods like: ✔️ find() → to get the index of a substring ✔️ in → to check existence ✔️ index() → similar to find but throws error if not found But instead of just using built-in functions, I tried to understand the internal logic behind searching 👇 Find the position of a substring without using built-in functions. 🧠 My Approach: Traverse the string Compare characters one by one Return index if match is found Return -1 if not found def my_find(s, sub): for i in r print(my_find("manuuuu", "u")) # Output: 3 ✨ What I learned: How searching works internally Difference between find() and index() Importance of logic building instead of relying on built-ins 📈 Small steps every day = Big growth over time! #Day36 #Python #CodingJourney #ProblemSolving #100DaysOfCode #Learning #Developers #Programming Rudra Sravan kumar
To view or add a comment, sign in
-
-
Finding Maximum Sum of k Consecutive Elements in Python Check out this simple sliding window trick to get the maximum sum of k consecutive numbers in an array. I used my own code to solve it: Python Copy code nums = [7,1,5,1,3,2] k = 3 n = len(nums) window = sum(nums[:k]) sums = window for i in range(k,n): window = window - nums[i-k] + nums[i] if sums < window: sums = window print(sums) How it works: Start with the sum of the first k numbers Slide the window by removing the first number and adding the next Keep track of the maximum sum Fast, simple, and efficient! #Python #DSA #Coding #Algorithms #LearnByDoing #DeveloperLife
To view or add a comment, sign in
-
Day 4/120 – I finally understood how Python actually “thinks” 🤯 For the past 3 days, I was learning concepts… But today, things started making sense. Because I learned this 👇 👉 Operators in Python Operators are what make your code “do something” Without them, Python is just… variables sitting idle 😅 Here’s what I explored today 👇 ➕ Arithmetic Operators → +, -, *, / Example: 10 + 5 = 15 📊 Comparison Operators → ==, !=, >, < Example: 10 > 5 → True 🧠 Logical Operators → and, or, not Example: (10 > 5) and (5 > 2) → True This is where logic begins 🔥 Now I can actually: ✔ Make decisions ✔ Compare values ✔ Build logic Feels like I unlocked a new level 🎮 Consistency > Perfection 💪 If you're learning, comment “LEVEL UP” 🚀 #Day4 #Python #DataAnalytics #LearningInPublic #CodingJourney #Consistency #Beginners
To view or add a comment, sign in
-
-
INSTEAD OF WASTING TIME AND TRYING TO GET FIGURES. WHY NOT USING CODE?? Sometimes, lecturers or organizations need to generate different sets of questions for multiple candidates, especially when working with matrices. However, this often requires a lot of manual effort and can be time-consuming. Why not simplify the process using NumPy in Python? With just a few lines of code, you can easily generate multiple variations of matrix-based questions efficiently and save valuable time. #randint is an inbuilt function of the random module of numpy #Syntax: np.random.randint(start, stop (rows, columns)) a=np.random.randint(2,30, (3,3)) b=np.random.randint(2,30, (3,3)) c=np.random.randint(2,30, (3,3)) d=np.random.randint(2,30, (3,3)) e=np.random.randint(2,30, (3,3)) #DataScience #Python #NumPy #Education #Automation
To view or add a comment, sign in
-
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