Test/Python(20220101~)
Day13_How to Debugging
kiostory
2022. 1. 18. 22:59
#Everyone gets bugs.
#1. Decribe the problem (문제 그려보기)
def my_function():
for i in range(1, 20): #20은 포함되지 않음, 아래 조건을 만족하려면 21로 수정
if i == 20:
print("You got it")
my_function()
#2. Reproduce the Bug (재 구현)
from random import randint
dice_imgs = ["❶", "❷", "❸", "❹", "❺", "❻"]
dice_num = randint(1, 6) # lists --> 0~5
print(dice_imgs[dice_num])
#3. Play Computer? Be a Computer!
year = int(input("What's your year of birth?"))
if year > 1980 and year < 1994: #1994년은 어디에도 해당하지 않음<=
print("You are a millenial.")
elif year > 1994:
print("You are a Gen Z.")
#4. Fix the Errors
age = input("How old are you?")
if age > 18: #숫자와 string을 비교
print("You can drive at age {age}.") #indented block 표현이 필요함,{age}표현을 위해 f-string필요
#5. 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)
#6. Use a Debugger #pythontutor.com, thonny
def mutate(a_list):
b_list = []
for item in a_list:
new_item = item * 2
b_list.append(new_item) #indented block
print(b_list)
mutate([1,2,3,5,8,13])
#유용한 디버깅 팁
Take a Break
Ask a Friend
Run Often 자주 실행
Ask StackOverflow