본문 바로가기

Python22

[Python_Bootcamp] 리스트 랜덤 추출 이 글은 Dr. Angela Yu의 [Python_Bootcamp]를 수강하며 정리한 글입니다. 👉 기본 환경 - Language: Python - IDE: Replit 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 #Password Generator Project import random letters = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'.. 2023. 8. 16.
[해결 방법] TypeError: 'int' object is not callable 👉 기본 환경 - Language: Python - IDE: Replit ⌨️ 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # 🚨 Don't change the code below 👇 student_scores = input("Input a list of student scores ").split() for n in range(0, len(student_scores)): student_scores[n] = int(student_scores[n]) print(student_scores) # 🚨 Don't change the code above 👆 #Write your code below this row 👇 max = 0; for score in student_scores.. 2023. 8. 15.
[해결 방법] TypeError: list indices must be integers or slices, not str 👉 기본 환경 - Language: Python - IDE: Replit ⌨️ 코드 1 2 3 4 5 6 7 position = input("Where do you want to put the treasure? ") col = position[0]; row = position[1]; map[row-1][col-1] = "X"; 🖨️오류 TypeError: list indices must be integers or slices, not str 📡 원인 리스트의 인덱스를 정수나 slices가 아닌 String을 사용 📰 해결 방법 1 2 3 4 5 6 7 position = input("Where do you want to put the treasure? ") col = int(position[0]); ro.. 2023. 8. 14.
[해결 방법] TypeError: list.count() takes exactly one argument 👉 기본 환경 - Language: Python - IDE: Replit ⌨️ 코드 1 2 3 list8 = ["do", "re", "mi", "mi"]; mi_cnt = list8.count(); 🖨️오류 TypeError: list.count() takes exactly one argument (0 given) 📡 원인 count()는 1개의 매개변수를 필요로 하는데, 매개변수가 없음 📰 해결 방법 1 2 3 list8 = ["do", "re", "mi", "mi"]; mi_cnt = list8.count("mi"); count()에 매개 변수로 list에서 개수를 구하고 싶은 요소 입력 2023. 8. 13.
[해결 방법] ValueError: list.remove(x): x not in list 👉 기본 환경 - Language: Python - IDE: Replit ⌨️ 코드 1 2 3 list = ["do", "re", "mi"]; list.remove("pa"); 🖨️오류 ValueError: list.remove(x): x not in list 📡 원인 list에 없는 요소를 삭제하려고 함 📰 해결 방법 1 2 3 list = ["do", "re", "mi"]; list.remove("mi"); list에 존재하는 요소를 삭제 2023. 8. 13.
[해결 방법] TypeError: 'int' object is not iterable 👉 기본 환경 - Language: Python - IDE: Replit ⌨️ 코드 1 2 3 list = [1, 2, 3] list.extend(4); 🖨️오류 TypeError: 'int' object is not iterable 📡 원인 list에서 extend는 iterable한 객체를 추가하고자 할 때 사용하므로 정수를 iterable한 객체로 사용하려고 해서 오류가 발생 * iterable한 객체: 순회 가능한 객체, 리스트, 튜플, 문자열과 같은 컨테이너 타입 📰 해결 방법 1 2 3 list = [1, 2, 3] list.extend("4"); 추가하려는 요소를 iterable한 객체로 변경 1 2 3 list = [1, 2, 3]; list.append(4); 모든 요소를 추가할 수 있는.. 2023. 8. 13.