SW.AI 트랙/python

[Python] 파이썬 예제풀이. for, 인텍스의 값/길이/문자 바꾸기

AI 봇 2023. 3. 13. 22:07

예제 1. for문을 사용해서 출석번호를 바꾸기

(조건)

1. 출석번호 students는 1, 2, 3, 4로 index 되어 있습니다.

2. 출석번호 앞에 새롭게 100을 붙이기로 합니다.

3. for문을 사용합니다.

 

(코딩)

students = [1,2,3,4]
print(students)
students = [i+100 for i in students]
print(students)

(출력)

[1, 2, 3, 4]
[101, 102, 103, 104]

 

 

예제 2. 학생 이름을 길이로 바꾸기

students = ["Kim kyung ho", "Parl Sungjong", "Lee chol"]
students = [len(i) for i in students]
print(students)

 

 

예제 3. 학생 이름을 대문자로 바꾸기

students = ["Kim kyung ho", "Parl Sungjong", "Lee chol"]
students = [i.upper() for i in students]
print(students)