🚀 Just built a simple Calculator using Python! Today I practiced basic programming concepts and created a calculator that can perform: ✅ Addition ✅ Subtraction ✅ Multiplication ✅ Division (with zero error handling) This project helped me understand: 🔹 if-elif-else conditions 🔹 User input handling 🔹 Basic error handling in Python Here’s a small snippet of my code 👇 num1 = float(input("Enter your first num: ")) num2 = float(input("Enter your second: ")) print("Select operation:") print("1 Add") print("2 Subtract") print("3 Multiply") print("4 Divide") choice = input("Enter choice (1/2/3/4): ") if choice == '1': print("Result:", num1 + num2) elif choice == '2': print("Result:", num1 - num2) elif choice == '3': print("Result:", num1 * num2) elif choice == '4': if num2 == 0: print("Error: Division by zero") else: print("Result:", num1 / num2) else: print("Invalid Input") Learning & Improving Every Day 🚀 💡 Today I practiced Python by building a simple calculator! Always exploring, always growing. #Python #Programming #Learning #Coding #Beginner #MdMoiz929
Python Calculator Project: Basic Operations and Error Handling
More Relevant Posts
-
🚀 Just built a simple Calculator using Python! Today I practiced basic programming concepts and created a calculator that can perform: ✅ Addition ✅ Subtraction ✅ Multiplication ✅ Division (with zero error handling) This project helped me understand: 🔹 if-elif-else conditions 🔹 User input handling 🔹 Basic error handling in Python Here’s a small snippet of my code 👇 num1 = float(input("Enter your first num: ")) num2 = float(input("Enter your second: ")) print("Select operation:") print("1 Add") print("2 Subtract") print("3 Multiply") print("4 Divide") choice = input("Enter choice (1/2/3/4): ") if choice == '1': print("Result:", num1 + num2) elif choice == '2': print("Result:", num1 - num2) elif choice == '3': print("Result:", num1 * num2) elif choice == '4': if num2 == 0: print("Error: Division by zero") else: print("Result:", num1 / num2) else: print("Invalid Input") Learning & Improving Every Day 🚀 💡 Today I practiced Python by building a simple calculator! Always exploring, always growing. #Python #Programming #Learning #Coding #Beginner #MdMoiz929
To view or add a comment, sign in
-
-
🚀 Just built a simple Calculator using Python! Today I practiced basic programming concepts and created a calculator that can perform: ✅ Addition ✅ Subtraction ✅ Multiplication ✅ Division (with zero error handling) This project helped me understand: 🔹 if-elif-else conditions 🔹 User input handling 🔹 Basic error handling in Python Here’s a small snippet of my code 👇 num1 = float(input("Enter your first num: ")) num2 = float(input("Enter your second: ")) print("Select operation:") print("1 Add") print("2 Subtract") print("3 Multiply") print("4 Divide") choice = input("Enter choice (1/2/3/4): ") if choice == '1': print("Result:", num1 + num2) elif choice == '2': print("Result:", num1 - num2) elif choice == '3': print("Result:", num1 * num2) elif choice == '4': if num2 == 0: print("Error: Division by zero") else: print("Result:", num1 / num2) else: print("Invalid Input") Learning & Improving Every Day 🚀 💡 Today I practiced Python by building a simple calculator! Always exploring, always growing. #Python #Programming #Learning #Coding #Beginner #MdMoiz929
To view or add a comment, sign in
-
-
🐍 Why One Version Works… and the Other Doesn’t (Python Classes Explained) Ever faced this situation while learning Python? 👇 One version of your class throws an error ❌ Another version works perfectly ✅ Let’s understand why 👇 🔴 First Case (Error) class Dog: def __init__(self, name, breed): self.name = name self.breed = breed john = Dog(name="Husk") 💥 This gives an error because: The constructor __init__ expects 2 arguments → name and breed But you only provided 1 argument 👉 Python says: “Hey, I’m missing breed!” 🟢 Second Case (Works Fine) class Dog: def __init__(self, name, breed="None"): self.name = name self.breed = breed john = Dog(name="Husk") ✅ This works because: breed now has a default value If you don’t pass it, Python automatically uses "None" 💡 Key Concept: Default Parameters When you assign a default value: The argument becomes optional Your code becomes more flexible 🎯 Simple Rule to Remember No default value → argument is required Default value given → argument is optional 🚀 Small concepts like these build strong programming foundations. Keep experimenting and breaking things—that’s how you really learn! #Python #Coding #Programming #Beginners #LearnToCode #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 Today I Learned: Operator Overloading in Python While exploring Object-Oriented Programming in Python, I came across an interesting concept — Operator Overloading. 👉 It allows us to define how operators like "+", "-", "*" behave for our own custom objects. 💡 Simple Idea: Instead of using operators only for numbers, we can use them for our own classes too! 🔧 Example: class Number: def __init__(self, value): self.value = value def __add__(self, other): return Number(self.value + other.value) def __str__(self): return f"{self.value}" n1 = Number(10) n2 = Number(20) print(n1 + n2) # Output: 30 🔥 Here, "+" is not just adding numbers — it’s calling "__add__()" behind the scenes! 📌 Key Takeaways: ✔ Operator overloading improves code readability ✔ Uses special methods (dunder methods like "__add__") ✔ Makes objects behave like real-world entities ✔ Important concept in OOP & interviews 💭 Learning how small features like this work internally really changes the way we write code. #Python #OOP #CodingJourney #100DaysOfCode #Programming #Learning
To view or add a comment, sign in
-
🚀 Day 4 of Learning Python Another productive day diving deeper into Python — today was all about control flow and strings 🔥 🔹 Loop Control Statements 1️⃣ Break – stops the loop immediately for i in range(5): if i == 3: break print(i) 2️⃣ Continue – skips the current iteration for i in range(5): if i == 3: continue print(i) 3️⃣ Pass – does nothing (placeholder for future code) for i in range(5): pass 🔹 Strings in Python 1️⃣ Length Function name = "Python" print(len(name)) # Output: 6 2️⃣ Indexing & Slicing text = "Hello World" print(text[0]) # H (indexing) print(text[0:5]) # Hello (slicing) 🔹 String Methods ✔️ Lowercase & Uppercase text = "Hello" print(text.lower()) # hello print(text.upper()) # HELLO ✔️ Strip (removes spaces) text = " Hello " print(text.strip()) # Hello ✔️ Replace text = "Hello World" print(text.replace("World", "Python")) ✔️ Startswith & Endswith text = "Hello World" print(text.startswith("Hello")) # True print(text.endswith("World")) # True 💡 Every day I’m getting closer to thinking like a programmer — small concepts, big impact. Consistency Day 4 ✅ Let’s keep growing! #Python #CodingJourney #LearnInPublic #Programming #Tech
To view or add a comment, sign in
-
🚀 Python Learning I used to think functions were complicated… Turns out, I was just overthinking. 👨🍳 Think of this: When you order food in a restaurant, you don’t go inside the kitchen and cook it yourself. You just give an order → and the chef handles everything. 💡 That’s exactly how functions work in Python. Instead of writing the same steps again and again, you define them once… and just “call” them whenever needed. 🔹 Example: def greet(name): print("Hello", name) greet("Dhanush") greet("Ram") greet("John") 🔥 What changed for me: Before functions → messy, repetitive code After functions → clean, reusable logic ⚠️ Mistake I made: I used to write everything in one long block. That’s not coding. That’s just typing more and creating bugs. #Python #Coding #Functions #LearningJourney Frontlines EduTech (FLM) Sai Kumar Gouru
To view or add a comment, sign in
-
-
🚀 Day 7 of My Python Learning Journey Today, I explored one of the most powerful and flexible data structures in Python — Lists 🐍 Think of a list like a smart container 📦 that can hold anything — numbers, strings, even mixed data — all in one place! 🔍 What I learned: ✨ Lists are ordered, mutable, and allow duplicates ✨ Represented using square brackets [ ] ✨ Supports indexing for easy access ✨ Can store heterogeneous elements 💡 Ways to take input into a list: Using loops (element by element) Using map() for single-line input (clean and efficient!) ⚙️ Explored Inbuilt Methods: 🔹 append() – Add elements at the end 🔹 clear() – Remove all elements 🔹 copy() – Create a new list (avoiding aliasing!) 🔹 count() – Count occurrences of an element 🔹 extend() – Merge lists 🔹 index() – Find position of an element 🔹 insert() – Add element at specific position 🔹 pop() – Remove elements (and return them!) 🧠 One small realization today: Lists aren’t just collections… they’re like mini toolkits that make data handling smooth and dynamic. 📈 Slowly building consistency, one concept at a time! #Python #CodingJourney #LearningInPublic #100DaysOfCode #PythonBasics #Programming #StudentLife #TechSkills
To view or add a comment, sign in
-
🚨 Python Tip: A Cleaner Way to Loop Most beginners write loops like this 👇 arr = [10, 20, 30] for i in range(len(arr)): print(i, arr[i]) ❌ Works… but not the best way ✅ Better & Pythonic way: arr = [10, 20, 30] for index, value in enumerate(arr): print(index, value) 🔍 Why this is better: ✔ Cleaner syntax ✔ More readable ✔ Less chance of errors ✔ Direct access to both index and value 🧠 Key Takeaway: Prefer enumerate() over range(len()) for looping through lists. Small improvement, big difference in code quality. ❓ Do you use enumerate() or still prefer range()? #Python #Programming #CodingTips #PythonTips #Developers #LearnPython
To view or add a comment, sign in
-
-
Hello connections 👋 Welcome to Day 2 of my Python problem-solving series! 🧠 Day 2 Challenge: Check if a number is Prime A prime number is a number greater than 1 that has only two factors: 1 and itself. 👉 Example: Input: 7 → Output: Prime Input: 9 → Output: Not Prime My Approach 1: Basic (Factor Counting Method) num = int(input("Enter a number: ")) c = 0 if num <= 1: print("Not prime") else: for i in range(1, num + 1): if num % i == 0: c += 1 if c == 2: print("Prime") else: print("Not prime") 📌 Explanation: Here, we count how many numbers divide num. If the count is exactly 2 → it’s a prime number. ⚡ My Approach 2: Optimized num = int(input("Enter a number: ")) if num <= 1: print("Not prime") else: for i in range(2, int(num**0.5) + 1): if num % i == 0: print("Not prime") break else: print("Prime") 📌 Explanation: Instead of checking all numbers, we only check up to √n, which makes the solution much faster for large inputs. Now it’s your turn 👇 Try solving it using your own approach or suggest improvements! Let’s learn and grow together 🚀 #Python #CodingChallenge #ProblemSolving #30DaysOfCode #Programming
To view or add a comment, sign in
-
🧠 Python Concept: * (Unpacking Operator in Functions & Lists) Write flexible code like a pro 😎 ❌ Traditional Way nums = [1, 2, 3] print(nums[0], nums[1], nums[2]) ❌ Problem 👉 Fixed length 👉 Not flexible ✅ Pythonic Way nums = [1, 2, 3] print(*nums) 👉 Output: 1 2 3 🧒 Simple Explanation Think of * like “unpacking a bag 🎒” ➡️ Takes all items out ➡️ Spreads them ➡️ Uses them individually 💡 Why This Matters ✔ Cleaner code ✔ Works with any length ✔ Very useful in functions ✔ Widely used in real projects ⚡ Bonus Examples 👉 Merge lists: a = [1, 2] b = [3, 4] merged = [*a, *b] print(merged) 👉 Function arguments: def add(x, y, z): return x + y + z nums = [1, 2, 3] print(add(*nums)) 🐍 Don’t handle items one by one 🐍 Unpack them smartly #Python #PythonTips #CleanCode #LearnPython #Programming #DeveloperLife #100DaysOfCode
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
This runs? The screenshot I mean