100일 간의 코드: 2022년을 위한 완전한 Python Pro 부트캠프 - 13일차(디버깅)

6815 단어

#####디버깅



# Describe Problem: Query is out of range, either change from 1, 20 to 1,21 or 0,21

def my_function():
    for i in range(1, 20):
        if i == 20:
        print("You got it")
 my_function()

# Reproduce the bug. List index out of range, Change randit (1, 6) to (0, 5)

from random import randint
 dice_imgs = ["❶", "❷", "❸", "❹", "❺", "❻"]
 dice_num = randint(1, 6)
 print(dice_imgs[dice_num])

# Play Computer. Change > and < to >= and <=

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.")

# Fix the Errors 
Add int to the input int(input("How old are you"))
Add = to if age >= 18:
change print statement indent to align with the if statement
Add f string to the print statement

age = input("How old are you?"))
 if age > 18:
 print(f"You can drive at age {age}.")

# Print is Your Friend. Change word_per_page == to word_per_page =

 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)

# Debugging
# indent b_list.append(new_item)as this line is outside of the function

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,4,8,13])

좋은 웹페이지 즐겨찾기