🚀Python programming language | Buggy code 🤯

A baby programmer
2 min readDec 29, 2023

Welcome to your channel. Today we’re going to check the 10 Buggy code of Python programming language. Are you ready ??

1. Code: Uninitialized Variables

a = b = 10
print(a, b)
print(c, d) # UndefinedVariables

2. Code: List Index Error

fruits = ['apple', 'banana', 'cherry']
print(fruits[3]) # IndexError: list index out of range

3. Code: UnboundLocalError

x = 10
def example():
print(x)
x = 5
example() # UnboundLocalError: local variable 'x' referenced before assignment

4. Code: Division by Zero

y = 10
z = 0
print(y / z) # ZeroDivisionError: division by zero

5. Code: KeyError

user = {'name': 'John', 'age': 25}
print(user['email']) # KeyError: 'email'

6. Code: Incorrect Conditional Looping

numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers)):
if numbers[i] == 4:
break
print(numbers[i+1:]) # prints [5] instead of [4, 5]

7. Code: AttributeError

class Dog:
def __init__(self, name, age):
self.name = name
self.age = age

dog = Dog('Max', 3)
print(dog.breed) # AttributeError: 'Dog' object has no attribute 'breed'

8. Code: TypeError

print('Hello' + 10) # TypeError: Can't convert 'int' object to str implicitly

9. Code: NameError

print(random_variable) # NameError: name 'random_variable' is not defined

10. Code: RecursionError

def recursive_function(x):
return recursive_function(x)

recursive_function(1) # RecursionError: maximum recursion depth exceeded

A big thanks to you for read this type!

You can follow me at | Telegram | GitHub | Medium |

--

--

A baby programmer

Teaching Programming codes and Computer science with A baby programmer