문제는 이러하다
# •emails에 ‘@‘가 포함되지 않은 경우 “Wrong” 출력
# •desc에 developer라는 문자열이 포함되어 있을 경우
# 이를 beginner로 변경하고 출력
# •students_count가 5명 이상일 경우 이 값을 5로 변경하고 “Exceed” 출력
emails=['kmh@','jhr@','ysh']
desc='for developer'
students_count=10
if '@' not in emails[0]:
print(emails[0],'wrong')
if '@' not in emails[1]:
print(emails[1],'wrong')
if '@' not in emails[2]:
print(emails[2],'wrong')
첫번째 문제는 not in 을 이용하여 emails 리스트 안의 문자열들을 구별하였다.
@가 없으면 해당 문자열과 wrong를 출력하도록 하였다.
if 'developer' in desc:
desc=desc.replace('developer','beginner')
print(desc)
두번째 문제는 in을 활용하여 developer이란 문자열이 포함된 변수를 찾고
replace를 이용하여 desc안의 문자열을 변경하였다.
if students_count >=5:
students_count=5
print('Exceed')
세번째 문제는 부등호를 사용하여 5보다 크거나 같은 숫자를 구별하고
맞다면 숫자를 5로 변경후 Exceed를 출력하였다.
'Python > 실습' 카테고리의 다른 글
| 파일 읽기 실습하기 (0) | 2023.09.20 |
|---|---|
| 문자열 formating 실습하기 (0) | 2023.09.20 |
| 제어문 응용 실습하기 (0) | 2023.09.19 |