728x90

👉 기본 환경

- 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(0len(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:
    if max < score:
        max = score;
print(f"The highest score in the class is: {max}");
 
print(max(student_scores));
 
 
 

 

 

🖨️오류

TypeError: 'int' object is not callable

 

 

📡 원인

max()를 사용하기 전에 max 변수를 정의하여 max()를 사용할 수 없게 됨

 

 

📰 해결 방법

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(0len(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_score = 0;
for score in student_scores:
    if max_score < score:
        max_score = score;
print(f"The highest score in the class is: {max}");
 
print(max(student_scores));
 
 
 

max 변수 이름을 max_score로 변경하여 max()와 중복되지 않게 함

 

⭐ 내장 함수와 변수명이 중첩되지 않도록 유의

 

728x90
728x90

👉 기본 환경

- 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]);
row = int(position[1]);
 
map[row-1][col-1= "X";
 
 
 

String을 int로 변환 후, 리스트의 인덱스로 사용

 

728x90
728x90

👉 기본 환경

- 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에서 개수를 구하고 싶은 요소 입력

 

728x90
728x90

👉 기본 환경

- 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에 존재하는 요소를 삭제

 

728x90
728x90

👉 기본 환경

- Language: Python

- IDE: Replit

 

 

⌨️ 코드

1
2
3
list = [123]
list.extend(4);
 
 

 

 

🖨️오류

TypeError: 'int' object is not iterable

 

 

📡 원인

list에서 extend는 iterable한 객체를 추가하고자 할 때 사용하므로 정수를 iterable한 객체로 사용하려고 해서 오류가 발생

* iterable한 객체: 순회 가능한 객체, 리스트, 튜플, 문자열과 같은 컨테이너 타입

 

 

📰 해결 방법

1
2
3
list = [123]
list.extend("4");
 
 

추가하려는 요소를 iterable한 객체로 변경

 

1
2
3
list = [123];
list.append(4);
 
 

모든 요소를 추가할 수 있는 append() 사용

 

728x90