#History: Grace Hopper probably one of the first programmers and one of the pioneers of the job
#describe the Problem
#Describe Problem
def my_function:
#for i in range(1,20):
for i in range(1,21):
# 這裡有邏輯上的錯誤, range最後的 number 是 20, 只會取到19, 若要取20的話, last number要是21
if i == 20:
print("You go it")
my_function()
#Reprodue the Bug
from random impoort randint
dice_imgs = ["1","2","3","4","5","6"]
dice_num = randint(1,6)
print(dice_imgs[dice_num])
#IndexError: list index out of range
#index of list maximum is 5
#index 6 of element is not exist in list, so that why it's out of range
#Playt Computer and Evaluate Each Line
year = int(input("what's your year of birth?"))
#if year > 1980 and year <= 1994:
if year > 1980 and year < 1994:
print("Yhour are a millenial.")
#elif year >= 1994:
elif year > 1994:
print("You are a Gen Z.")
#Print nothing above code due to once year = 1994 no condition be matched
#Fixing Errors and Watching for Red Underlines
#age = input("How old are you")
age = int(input("How old are you"))
#TypeError, age shall be int type
if age > 18:
# Identation error
#print(f"You can drive at age {age}.")
print(f"You can drive at age {age}.")
#Squash bugs with a print() Statement
note:
pages = 0
word_per_page = 0
pages = int(input("Number of apges: "))
#邏輯錯誤, 以下這行等於0
#word_per_page == int(input("Number of words per page : "))
#應改成如下=
word_per_page = int(input("Number of words per page : "))
total_words = pages * word_per_page
#Print is your friend
print(f"pages = {pages}")
print(f"word_per_page = {word_perpage}")
print(total_words)
#Bringing out the Big Gun: Using a Debugger
Python Tutor - Visualize Python, Java, JavaScript, C, C++, Ruby code execution