Arama Sonuçları: "#pythonpuzzle"

20 sonuç
Ankit Aggarwal
Ankit Aggarwal@TechAheadAnkit·
Python puzzle for you all 🐍 What will this print? a = [[1]] * 3 a[0][0] = 99 print(a) Reply with your answer + explanation (or code fix)! Bonus: How to create 3 independent lists instead? Don't cheat by executing on Python console #Python #CodingChallenge #PythonPuzzle
English
1
0
1
143
SkillzRevo
SkillzRevo@skillzrevo89393·
Python Puzzle (List Comprehension + Slicing) 📷 Python Puzzle Time! What’s the output of this list comprehension twist? print([x for x in range(5) if x % 2 == 0][::-1]) 📷 Slice, dice, and conquer the logic! Drop your answer below 📷 #Skillzrevo #PythonPuzzle #CodingFun #SliceAndDice 📷 skillzrevo.com
SkillzRevo tweet media
English
0
0
0
3
CodeWithWhy | Think Outside the Code
Python Puzzle: The Mysterious List Why does this function return [1] on the first call but [1, 1] on the second? Can you spot the bug? Think you know? Reply with your answer! #PythonPuzzle
CodeWithWhy | Think Outside the Code tweet media
English
0
0
1
76
Datafrik
Datafrik@datafrik_co·
🎭 Welcome to 'CSI: Code Squad Investigation' 🕵️‍♀️🖥️ This image shows a Lambda function designed to find the square of a number. But there's a sneaky bug 🐞lurking within. Can you identify it? Best detective 👮wins bragging rights! #pythonpuzzle #datafrik #codechallenge
Datafrik tweet media
English
1
2
3
595
Oscar
Oscar@oskrgab·
Last week’s #PythonPuzzle was about whether a simple Python expression resulted in True or False: 🧐 >>> 0.1 + 0.2 == 0.3 And most people who answered the poll got the correct result, False. 👍 But why is it False? What happens if you run the following? 🤔 >>> 1 + 2 == 3 This one yields True, as expected. 😎 The underlying objective of this question was to uncover an important yet overlooked topic for self-taught programmers: Floating Point Arithmetic. ------------------------------------------- Numbers like 0.1 are double-precision floating-point numbers. These numbers are represented in computers as binary fractions. In the case of 0.1, its base 2 representation is the following repeating: 0.000110011001100110011...... Since computers have finite precision, you'll always get an approximate decimal representation of these numbers stored in base 2. This doesn't only happens in Python, it happens for all programming languages. This is why, when you add 0.1 + 0.2, it doesn't exactly add up to 0.3. -------- I recall encountering this behavior the second day I started programming in Python (about 7 years ago). Specifically, when I was trying to create relative permeability tables, for which I had to use Swirr and 1-Sor as starting and end points to populate the values. As you might imagine, values such as 0.1, 0.2, 0.3 are common values for Swirr and Sor, and the script was not generating the values in the correct places, because of these type of comparison (Swirr == 0.1). --------- The good news is that, if you need better precision for these types of calculations or comparisons, you might want to look at Python's Decimal and Fraction modules. We'll talk more about those in future posts, but in the meantime here are some useful links you can start checking out. - Floating Point Arithmetic: docs.python.org/3/tutorial/flo… - Decimal Module: docs.python.org/3/library/deci… - Fractions Module: docs.python.org/3/library/frac… Did you come across this behavior while working with Python? What is your experience? Feel free to share it in the comments.
Oscar tweet media
English
0
0
0
61
Oscar
Oscar@oskrgab·
🚨 #PythonPuzzle Answer: Why `ZeroDivisionError` is the Culprit! 🐍 Last week, we put our heads together to solve a Python code challenge. The function was simple: calculate a flow rate given a volume and time. But what happens when time equals zero? Let’s break it down: ❌ Infinity? Nope. In Python, dividing by zero doesn't result in infinity. Unlike some other environments that may return an infinite value when dividing by zero, Python doesn’t follow that convention. ❌ 0? Incorrect. Mathematically, division by zero is undefined. It’s not zero because you can’t have a rate of change with no time elapsed - it's an indeterminate form. ❌ ValueError? Almost! Our function does check for negative time and would raise a `ValueError` if that were the case. But zero isn't negative, so this error won’t be raised. ✅ ZeroDivisionError! Bingo! 🎯 In Python, attempting to divide by zero triggers a `ZeroDivisionError`. It’s Python's way of saying, "Hold up, you can’t do that!" The key takeaway? Always check your inputs and remember that Python has built-in exceptions for a reason. They prevent operations that can lead to undefined or unexpected behavior. Happy coding, and stay tuned for the next #PythonPuzzle! 🧩 Previous post: x.com/oskrgab/status… #engineering #programming #python #coding #learnpython #development
Oscar tweet media
English
0
0
2
52
Bhautik Bavadiya
Bhautik Bavadiya@yesbhautik·
Can you crack this? What will the output be if you start counting from 0 and increment by 3 until you hit 30 in Python? A twist: how about if we decrement by 2 from 30? Test your coding skills! 💻🔎 #CodingChallenge #PythonPuzzle
Bhautik Bavadiya tweet media
English
0
0
1
17