🚀 Day 3 – Python Practice Progress( 6 of 50 questions solved) Problems I practiced today: ✔ Check if a number is even or odd ✔ Find the largest of three numbers ✔ Print numbers from 1 to N ✔ Find the sum of numbers from 1 to N ✔ Check if a number is prime ✔ Check if a string is a palindrome While solving these, I practiced using: • Conditional statements • Loops (while / for) • Input validation using try–except • String slicing (for palindrome checking) 💡 One interesting concept I explored today was Python slicing: s = "python" print(s[::-1]) This reverses the string because the step -1 makes Python traverse the sequence backwards. Small problems like these are helping me build stronger problem-solving skills in Python. Looking forward to practicing more tomorrow. #Python #DataScience #Programming 1 Check if a number is even or odd. try: num1=int(input("Enter a Number : ")) if num1%2==0: print("number is even") else: print("number is odd") except ValueError: print("invalid input. Please enter a number") 2. Find the largest of three numbers. try: num1=int(input("Enter first Number: ")) num2=int(input("Enter second Number: ")) num3=int(input("Enter third Number: ")) if num1>num2 and num2>num3: print("Larget Number is :", num1) elif num2>num3 and num2>num1: print("Largest Number is :", num2) else: print("Largest Number is :", num3) except ValueError: print("invalid Input. Please enter a number") 3 Print numbers from 1 to N try: num1=int(input("Enter a Number: ")) if num1>0: s=0 while s<=num1: print(s) s=s+1; else: p=0 while p>=num1: print(p) p=p-1; except ValueError: print("invalid input, please enter a number") 4 Find the sum of numbers from 1 to N. try: num=int(input("Enter a number : ")) if num>0: s=0 i=0 while i<=num: s=s+i; i=i+1; print(s) else: p=0 q=0 while q >=num: p=p+q; q=q-1; print(p) except ValueError: print("invalid input. Enter correct Number") Check if a number is prime. try: num=int(input("Enter a number : ")) if num>1: is_prime=True i=2 while i <num: if num%i==0: is_prime=False break i=i+1 if is_prime: print("Number is prime") else: print("Number is not prime") else: print("Enter a number greater than 1") except ValueError: print("Invalid Input. enter valid number") 6. Check if a string is a palindrome. try: num=str(input("Enter a sring:")) if num==num[::-1]: print("Palindrome") else: print("not a palindrome") except ValueError: print("invalid input. Enter a string")
Python Practice Progress: 6/50 Questions Solved
More Relevant Posts
-
🧙♂️ Magic Methods in Python (Dunder Methods) Python is known for its powerful and flexible object-oriented features. One of the most interesting concepts in Python is Magic Methods, also called Dunder Methods (Double Underscore Methods). Magic methods allow developers to define how objects behave with built-in operations such as addition, printing, comparison, and more. These methods always start and end with double underscores (__). Example: __init__ __str__ __add__ __len__ They are automatically called by Python when certain operations are performed. --- 🔹 Why Magic Methods are Important? Magic methods help to: ✔ Customize the behavior of objects ✔ Make classes behave like built-in types ✔ Improve code readability ✔ Implement operator overloading They allow developers to write clean, powerful, and Pythonic code. --- 🔹 Commonly Used Magic Methods 1️⃣ __init__ – Constructor This method is automatically called when an object is created. class Student: def __init__(self, name): self.name = name s = Student("Vamshi") --- 2️⃣ __str__ – String Representation Defines what should be displayed when we print the object. class Student: def __init__(self, name): self.name = name def __str__(self): return f"Student name is {self.name}" s = Student("Vamshi") print(s) --- 3️⃣ __len__ – Length of Object Allows objects to work with the len() function. class Team: def __init__(self, members): self.members = members def __len__(self): return len(self.members) t = Team(["A", "B", "C"]) print(len(t)) 4️⃣ __add__ – Operator Overloading Defines how the + operator works for objects. class Number: def __init__(self, value): self.value = value def __add__(self, other): return self.value + other.value n1 = Number(10) n2 = Number(20) print(n1 + n2) 🔹 Key Takeaway Magic methods make Python classes more powerful and flexible by allowing objects to interact naturally with Python's built-in operations. Understanding magic methods helps developers write cleaner and more advanced object-oriented programs. #Python #PythonProgramming #MagicMethods #DunderMethods #OOP #Coding #LearnPython #SoftwareDevelopment
To view or add a comment, sign in
-
-
🐍 30 Python Challenges to Test Your Skills! 💻 1️⃣ Reverse a string without using loops 🔄 2️⃣ Count duplicates in a list 📝 3️⃣ Flatten a nested list 📂 4️⃣ Find all prime numbers up to N 🔢 5️⃣ Check if a string is a palindrome 🔁 6️⃣ Swap two variables in Python ⚡ 7️⃣ Merge two dictionaries efficiently 🗂️ 8️⃣ Remove all vowels from a string ✂️ 9️⃣ Sort a list of dictionaries by a key 🔑 🔟 Generate Fibonacci numbers in one line 🔢 1️⃣1️⃣ Find the most common element in a list 📊 1️⃣2️⃣ Remove duplicates while preserving order ✅ 1️⃣3️⃣ Find largest & smallest number without min()/max() 🔝🔽 1️⃣4️⃣ Count character occurrences in a string 🔡 1️⃣5️⃣ Reverse words in a sentence 🔁 1️⃣6️⃣ Check if two strings are anagrams 🔤 1️⃣7️⃣ Check if a number is a perfect square ◼️ 1️⃣8️⃣ Transpose a 2D list (matrix) 🔄 1️⃣9️⃣ Convert a list of strings to integers, ignoring invalid inputs 🔢 2️⃣0️⃣ Filter even numbers from a list ✨ 2️⃣1️⃣ Calculate factorial using recursion or loops 🔁 2️⃣2️⃣ Check if a number is prime efficiently 🔢 2️⃣3️⃣ Generate all subsets of a list 📂 2️⃣4️⃣ Capitalize the first letter of each word ✍️ 2️⃣5️⃣ Merge two sorted lists into one sorted list 🗂️ 2️⃣6️⃣ Find second largest number in a list 🔝 2️⃣7️⃣ Count vowels in a string 🔡 2️⃣8️⃣ Check if a list is sorted ✅ 2️⃣9️⃣ Find indices of all occurrences of an element 📌 3️⃣0️⃣ Check if a string is a pangram 🔠 💡 Pro Tip: The most Pythonic solutions often use list comprehensions, sets, dictionaries, and built-in functions. ⚡ Try them out and comment your favorite solution! Don’t forget to share tips & tricks you use daily in Python. 🔁 Repost to help others learn faster ❤️ Like if you found it useful 📥 Save it for future reference 👥 Tag someone who needs this! #Python 🐍 #Programming 💻 #CodingChallenge 🚀 #Developers 👨💻 #TechInnovation 💡 #AI 🤖 #MachineLearning 🧠 #DataScience 📊 #Automation ⚡#SoftwareEngineering 💻 #ProgrammingLife 📝 #TechTrends 📈 #PythonTips 🐍 #LearnToCode 📚 #ProblemSolving 🧩 #DeveloperCommunity #TechSkills ⚡ #PythonProgramming 🐍
To view or add a comment, sign in
-
🐍 Python Practice – Day 3 ( 14 out of 50 questions solved) Continuing my Python learning journey and focusing on strengthening problem-solving skills through small coding exercises. 📌 Problems solved today: 🔹 Count vowels in a string 🔹 Reverse a number 🔹 Print the multiplication table of a number 🔹 Find the factorial of a number 📌 List-based problems: 🔹 Find the largest element in a list 🔹 Find the second largest number in a list 🔹 Remove duplicates from a list Each exercise helps improve my understanding of loops, conditions, lists, and basic Python logic. Consistency is the key, and I’m enjoying the process of learning step by step. Looking forward to tackling more problems tomorrow! 🚀 #Python #PythonLearning #CodingPractice Day 2 Count vowels in a string. try: word=str(input("enter a string")).lower() vowel={'a','e','i','o','u'} s=0 for i in word: if i in vowel: s=s+1 print(s) except ValueError: print("Invalid input. enter string") Reverse a number. try: num1 =str(input("Enter a number: ")) num2=num1[::-1] print(num2) except ValueError: print("invalid input. enter a number") Print multiplication table of a number. try: num=int(input("enter a number")) s=1 mult=0 while s<=10: mult=num*s s=s+1 print(mult) except ValueError: print("invalid input") Find factorial of a number. try: num=int(input("enter a number")) fact=1 while num>0: fact=fact*(num) num=num-1 print(fact) except ValueError: print("invalid input") Find the largest element in a list. try: list1=[1,2,3,4,5,6,7,8,898] print(max(list1)) except ValueError: print("error occured. Please check the code") Find the second largest number in a list. try: list1=[1,2,3,4] largest=max(list1) secondlargest=float('-inf') for i in list1: if i != largest and i >secondlargest: secondlargest=i print(secondlargest) except ValueError: print("error occured. Please check the code") Remove duplicates from a list. try: list1=[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8] set1=set(list1) print(list(set1)) except ValueError: print("invalid operation")
To view or add a comment, sign in
-
🧠 Python doesn’t “free memory”. It negotiates with it. Most developers know that Python has Garbage Collection. Very few know how it actually works internally. Let’s break it down. 1. Reference Counting (Primary Memory Manager) At the core of Python’s memory management is reference counting. Every object in Python maintains a counter that tracks how many references point to it. Example: a = [1,2,3] b = a Now the list object has 2 references. Internally (in CPython): PyObject ├── ob_refcnt ← reference count └── ob_type Whenever a new reference is created → refcnt +1 Whenever a reference is deleted → refcnt -1 When the count hits 0, Python immediately deallocates the object. That’s why: a = [1,2,3] del a Memory is freed instantly. ⚡ This makes Python’s memory management very fast and deterministic. But there is a problem. 2. The Circular Reference Problem Reference counting cannot detect cycles. Example: a = [] b = [] a.append(b) b.append(a) Even if you delete both: del a del b Both objects still reference each other. So their reference count never reaches 0. Memory leak. This is where Python’s Garbage Collector comes in. 3. Generational Garbage Collector Python adds a cycle detector on top of reference counting. It uses a generational model. Objects are divided into 3 generations: Generation 0 → New objects Generation 1 → Survived one GC cycle Generation 2 → Long lived objects Why? Because most objects die young. This is called the Generational Hypothesis. So Python runs GC more frequently on young objects. Example thresholds: Gen0 threshold ≈ 700 allocations Gen1 threshold ≈ 10 Gen0 collections Gen2 threshold ≈ 10 Gen1 collections This keeps GC fast and efficient. 4. How Cycle Detection Works Internally Python uses a mark-and-sweep style algorithm. Steps: 1️⃣ Identify container objects (lists, dicts, classes) 2️⃣ Track references between them 3️⃣ Temporarily reduce reference counts 4️⃣ Objects that reach zero → unreachable cycle 5️⃣ Free them All of this is implemented in: Modules/gcmodule.c Inside CPython. 5. Interesting Internals You can actually inspect GC behavior: import gc gc.get_threshold() gc.get_count() gc.collect() You can even disable GC: gc.disable() Which some high-frequency trading systems and low latency apps do to avoid GC pauses. (Manual control > unpredictable pauses) 6. Why Python Rarely Leaks Memory Because it combines: ✔ Reference counting (instant cleanup) ✔ Generational GC (cycle detection) This hybrid model makes Python one of the most predictable memory managers among dynamic languages. Most developers use Python. Very few explore CPython internals. But once you understand things like: • PyObject • reference counters • generational GC You start seeing Python less like a language… and more like a beautifully engineered runtime system. #Python #CPython #GarbageCollection #Programming #PythonInternals #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 3 of My Python Learning Journey. Today was a very productive day as I continued building my Python fundamentals. Instead of just reading theory, I focused on writing code and practicing small programs to understand how Python actually works. Here are the key concepts I explored today: 🔹 Python Data Types I learned about the fundamental data types in Python such as: • Integer • Float • String • Boolean Understanding data types is important because they determine how Python stores and processes different kinds of data. 🔹 Type Conversion in Python One of the most interesting things I learned today was type conversion. Since the input() function always takes values as strings, I practiced converting them into the required data types using: • int() → convert to integer. • float() → convert to decimal number. • str() → convert to string. This is extremely important when building programs that perform calculations based on user input. These are of two types : Implicit (automatic in python) and Explicit (manual in python). 🔹 Operators in Python I explored operators and how Python performs calculations: • Arithmatic Operator -(+,-,*,/,%) • Comparison Operator - (==,!=,<=,>=,<,>) • Logical Operator - (and , or , not) • Assignment Operator - (=,+=,-=,*=,/=,%=,**=, //=) Understanding operators helps in writing programs that perform mathematical and logical operations. 🔹 Practice Problems To strengthen my understanding, I solved multiple practice programs including: • Writing a program to add two numbers. • Working with variables and expressions. • Practicing user input and calculations. 🔹 Assignment Problem I also completed an assignment where I built a small program that: ✔ Takes temperature input in Celsius from the user. ✔ Converts it into Fahrenheit using the formula. ✔ Converts it into Kelvin as well. Programs like these may look simple, but they help build the foundation for problem solving and logical thinking in programming. 📂 Today’s coding practice included creating multiple Python files in VS Code to organize my learning and experiments. What I’m realizing is that consistent daily practice is the real key to mastering programming. My goal is to build a strong Python foundation and eventually use it in Artificial Intelligence and Machine Learning. Step by step. Day by day. Code by code. Looking forward to learning more tomorrow. 🚀 #Python #PythonLearning #CodingJourney #LearnToCode #Programming #ComputerScience #TechLearning #AI #MachineLearning #FutureEngineer
To view or add a comment, sign in
-
-
Most people learning Python struggle with one thing: Classes. This is not due to how class definitions function or their complexity, but is mainly because they are typically explained in a complicated fashion. I recently shared an article where I break down Python classes in the simplest way possible — from basics to intuition, without unnecessary jargon. Furthermore, understanding class definitions is important in Python and as such is also a requirement when writing scalable/dependable systems. If you're learning Python or transitioning into ML, this will make things much clearer. What concept in Python took you the longest to truly understand? ♻️ Repost if you’re betting on yourself this time. ➕ Follow me, Samith Chimminiyan, for such ML-related content. Learning in public 🚀 #Python #MachineLearning #DataScience #Programming #OOP #LearnToCode #Developers
To view or add a comment, sign in
-
🚀 Day 8 of Learning Python: Error Handling 💻 ✅ Back with a learning update 👉 Today I explored how Python handles errors gracefully using exception handling. This helps prevent programs from crashing and improves user experience. 🔹 Common Python Errors: ZeroDivisionError → Dividing by zeroValueError → Invalid input (e.g., text instead of number)TypeError → Wrong data type usedFileNotFoundError → File does not exist 💡 1. Simple Error Handling try: num = int(input("Enter number: ")) print(10 / num) except: print("Error occurred!")👉 Prevents the program from crashing on invalid input 💡 2. Handling Specific Errors try: num = int(input("Enter number: ")) print(10 / num) except ZeroDivisionError: print("Cannot divide by zero!") except ValueError: print("Please enter a valid number!") 💡 3. Using else try: num = int(input("Enter number: ")) except ValueError: print("Invalid input") else: print("You entered:", num)👉 else runs only when no exception occurs 💡 4. Using finally try: file = open("data.txt") except FileNotFoundError: print("File not found!") finally: print("Execution completed")👉 finally always executes (useful for cleanup) 💡 5. Handling Multiple Errors Together try: a = int(input()) b = int(input()) print(a / b) except (ValueError, ZeroDivisionError): print("Invalid input or division by zero") ⚡ Raising Your Own Error age = int(input("Enter age: ")) if age < 18: raise Exception("You must be 18+") 🔥 Custom Exception (Advanced) class MyError(Exception): pass try: raise MyError("Something went wrong") except MyError as e: print(e) ✅ Key Takeaway: Error handling makes your programs more robust, user-friendly, and professional. #Python #CodingJourney #LearnPython #30DaysOfCode #Programming
To view or add a comment, sign in
-
Python dict: Fast Lookups and How Collisions Are Handled The "dict" is one of the most powerful and frequently used data structures in Python. It provides average O(1) time complexity for lookups, insertions, and deletions. But how does it stay so fast? Under the hood, a Python dictionary is implemented as a hash table. When you insert a key into a dictionary, Python first computes a hash value using the "hash()" function. This hash determines where the key–value pair should be placed in the internal table. However, different keys can sometimes produce the same hash index. This situation is called a hash collision. Python handles collisions using a technique called open addressing. Instead of storing multiple elements in the same bucket (like chained hash tables), Python searches for the next available slot in the table using a probing sequence. The simplified process looks like this: 1. Compute the hash of the key 2. Map the hash to an index in the table 3. If the slot is occupied, probe another position 4. Continue probing until an empty slot or the key itself is found Python dictionaries also maintain performance by resizing the table when it becomes too full. When the load factor increases, the dictionary allocates a larger table and rehashes the existing keys. This design allows Python dictionaries to remain extremely fast even with millions of entries. Understanding how collisions are handled helps explain why "dict" is both efficient and reliable for real-world applications. What’s the most interesting thing you’ve learned about Python dictionaries?
To view or add a comment, sign in
-
🐍 Python Practice Progress ( 21 out of 50 question solved) Here are the problems I recently solved: ✅ Count even and odd numbers in a list ✅ Reverse a list without using reverse() ✅ Insert the third largest number at the second last position in a list. ✅ Find the sum of all elements in a list ✅ Merge two lists ✅ Find common elements between two lists ✅ Sort a list without using sort() Working through these exercises helped reinforce concepts like: • loops and indexing • list operations • conditional logic • problem-solving without relying on built-in shortcuts Sometimes going back to the basics is the best way to build stronger foundations. Day 3 ------------------- Count even and odd numbers in a list. try: Num1=[1,2,3,4,5,6,7,8,9,9,88] even=0 odd=0 for i in Num1: if i%2==0: even=even+1 elif i%2!=0: odd=odd+1 print("even are ",even) print("odd are ", odd) except ValueError: print("Some error occured.") Reverse a list without using reverse(). list1=[1,2,3,4,5,6,7] rev_list=[] rev_list=list1[::-1] print(rev_list) # or try: list1=[1,2,3,4,5,6,7] rev_list=[] for i in list1: rev_list.insert(0,i) print(rev_list) except ValueError: print("error occured.") or try: list1=[1,2,3,4,5,6,7] rev_list=[] for i in range(len(list1)-1,-1,-1): rev_list.append(list1[i]) print(rev_list) except ValueError: print("error occured.") Insert third largest number in a list and add it at second last position. try: list1=[1,2,76,84,989,23,4,5,666,7,788,8,9897] third_largest=sorted(list1)[-3] list1.insert(len(list1)-1,third_largest) print(list1) Find the sum of all elements in a list. try: list1=[2,4,5,4,44,33,65,898,90] s=0 for i in list1: s=s+i print(s) except ValueError: print("error occured") Merge two lists. try: list1=[2,3,4,4,5,6,7] list2=[99,8,0,4,2,1] c=list1+list2 print(c) except ValueError: print("error occured") using extend method try: list1=[2,3,4,4,5,6,7] list2=[99,8,0,4,2,1] list1.extend(list2) print(list1) except ValueError: print("error occured") # Find common elements between two lists. try: list1=[2,3,4,4,5,6,7] list2=[99,8,0,4,2,1] list3=set(list1).intersection(set(list2)) print(list(list3)) except ValueError: print("error occured") Sort a list without using sort(). try: list2=[99,8,0,4,2,1] for i in range(len(list2)): for j in range(len(list2)-1): if list2[j]>list2[j+1]: list2[j],list2[j+1]=list2[j+1],list2[j] ---i am using bubble sort logic print(list2) except ValueError: print("error occured") #Python #CodingPractice #PythonProgramming #ProblemSolving #DataScienceJourney
To view or add a comment, sign in
-
Start learning Python by writing code. Not by watching tutorials. Not by saving playlists. Actually writing code. Because Python looks simple on the surface… but the real value comes when you start using it. Most people stop at basics like: print statements loops if-else And then say “I know Python.” But real understanding starts when you go deeper. When you learn things like: • how data structures actually behave • how functions organize logic • how OOP helps structure real systems • how APIs, files, and databases connect to code • how automation and scripting solve real problems That’s when Python starts becoming useful. This PDF is helpful because it doesn’t just show syntax. It walks through Python step-by-step — from fundamentals to real-world concepts like APIs, file handling, multithreading, and more. :contentReference[oaicite:0]{index=0} So instead of jumping between random tutorials, you can build understanding in one structured flow. A simple way to use it: 1. Pick one concept 2. Write code for it 3. Modify it and break it 4. Try to apply it in a small use case That’s how skills actually stick. Because Python is not about knowing everything. It’s about being able to use it when needed. And that only happens through practice. Not passive learning. Save this sheet so you can revisit it while practicing. Comment "Python" and I’ll send the full PDF. Follow Sahil Hans for daily tech job openings and practical interview prep resources that make switching easier.
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