removing bugs from your code
*comment, un-comment : ctrl + /
def my_function():
for i in range(1, 20):
if i == 20:
print("You got it")
my_function()
<debugged>
# Describe Problem
def my_function():
for i in range(1, 21):
if i == 20:
print("You got it")
my_function()
randint: endpoint doesn't deduct -1, unlike range, to reproduce the bug, we put end number to see if it produces error sign.
from random import randint
dice_imgs = ["❶", "❷", "❸", "❹", "❺", "❻"]
dice_num = randint(1, 6)
print(dice_imgs[dice_num])
#<debugged>
# Reproduce the Bug
from random import randint
dice_imgs = ["❶", "❷", "❸", "❹", "❺", "❻"]
dice_num = randint(0, 5)
print(dice_imgs[dice_num])
pretend you are a computer, and think like computer.
let's say input year is 1994, it deosn't belong to any of the condition.
if you put it in a if statement, 1994>1980 ? => True, 1994 >1994 ? => False, True and False => Flase
year = int(input("What's your year of birth?"))
if year > 1980 and year < 1994:
print("You are a millenial.")
elif year > 1994:
print("You are a Gen Z.")
<debugged>
# Play Computer
year = int(input("What's your year of birth?: "))
if year >= 1980 and year <= 1994:
print("You are a millenial.")
elif year > 1994:
print("You are a Gen Z.")
Google it: TypeError: '>' not supported between instances of 'str' and 'int'
# Fix the Errors
age = input("How old are you?")
if age > 18:
print("You can drive at age {age}.")
#TypeError: '>' not supported between instances of 'str' and 'int'
<debugged>
age = int(input("How old are you?: "))
if age > 18:
print(f"You can drive at age {age}.")
Print variables from time to time
# #Print is Your Friend
pages = 0
word_per_page = 0
pages = int(input("Number of pages: "))
word_per_page == int(input("Number of words per page: "))
total_words = pages * word_per_page
print(total_words)
#<debugged>
#Print is Your Friend
pages = 0
word_per_page = 0
pages = int(input("Number of pages: "))
word_per_page = int(input("Number of words per page: "))
total_words = pages * word_per_page
print(pages)
print(word_per_page)
print(total_words)
Use a debugger
http://pythontutor.com/visualize.html#mode=display
#Use a Debugger
def mutate(a_list):
b_list = []
for item in a_list:
new_item = item * 2
b_list.append(new_item)
print(b_list)
mutate([1,2,3,5,8,13])
#<debugged>
def mutate(a_list):
b_list = []
for item in a_list:
new_item = item * 2
b_list.append(new_item)
print(b_list)
mutate([1,2,3,5,8,13])
if you starting at the code for a long time, then your brain won't work. Have some down time, and come back to it, everything gets so obvious.
With fresh eyes, your friends can help you.
Don't wait until you write loads of codes. Run and confirm.
leave it all to the end and end up with pile of bugs..
Bug or issue should be unique. if not, just search. Vital tool!
you only wanna ask a question when you've pretty sure that you've exhausted all other avenues of debugging and you've searched all of Stack Overflow.
This is very interesting and your commitment genuine. I think you are so trusted -
https://www.delhicallgirls.net/
I am Jiya Roy a joy of babes in Kolkata.
https://jiyaroy.in/
It is a great and nice commitment by the people those who are looking to move forward with the things here.
https://www.aliasharma.in/