Debugging the python code contd
- Debugging is meant for finding and fixing mistakes in program
- Mistakes:
- Syntax Error
- Runtime Error
- Logical Error
Debugging Exercises
Exercise -1
- Create a new folder an open this folder in vscode
- Create a file called as
debug1.py -
Refer Here for the changes
-
Refer Here for the code after fix
Exercise – 2
- Code
numbers = [10, 20, 30, 40]
total = 0
for number in numbers:
total = total + number
average = total / len(numbers)
print(f"Total: {total}")
print(f"Average: {average}")
- Debug this
Exercise – 3
- Function debugging: step into
def calculate_discount(price, discount):
final_price = price - discount
return final_price
amount = calculate_discount(100, 10)
print(f"Total Amount after discount {amount}")
Debug and findout whats the problem in the following code
- Exercise 1
marks = [ 80, 90, 70 ]
total = 0
for mark in marks:
total = mark
average = total/len(marks)
print(average)
- Exericise 2
username = "admin"
password = "admin@123"
input_username= "admin"
input_password = "wrong@123"
if username == input_username or password == input_password:
print("Login Successful")
else:
print("Login Failed")
- Exercise 3
def find_largest(numbers):
largest = 0
for number in numbers:
if number < largest:
largest = number
return largest
values = [10,20,30,40,50]
result = find_largest(values)
print(result)
- Debug above 3 python codes given by creating a file and findout what an issue is
- Note: IMportance is procedure
