Notice
Recent Posts
Recent Comments
Link
160x600
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 머신러닝
- 예측
- 회귀모델
- DB
- python
- tensorflow
- sklearn
- Deep Learning
- 데이터베이스
- 데이터 분석
- 데이터 수집
- Database
- MariaDB
- 크롤링(crawling)
- 해석
- 알고리즘기초
- pandas
- 딥러닝
- 훈련
- 데이터
- 시각화
- 정확도
- 데이터 가공
- keras
- 파이썬
- python기초
- SQL예제
- 데이터전처리
- pythone
- HeidiSQL
Archives
- Today
- Total
코딩헤딩
python (반복문while, list) 본문
728x90
7명의 심판의 점수를 받아서 최소, 최댓값을 뺴는 프로그램
최소, 최댓값이 빠진 점수의 평균구하기
*요구사항
7멍의 심판들의 점수를 입력받아 리스트에 저장
7번의 input필요
입력값을 리스트에 저장
최대 최소값 찾기
평균 구하기
scores = list()
count = 0
while count < 7:
count += 1
point = input(f'{count}번째 심사위원 점수를 입력해 주세요:')
# if point.isdigit():
if point.replace('.','').isdecimal():
scores.append(float(point))
min = min(scores)
max = max(scores)
scores.remove(min)
scores.remove(max)
print(min, max)
print(scores)
avg = sum(scores)/len(scores)
print(f'평균은 : {avg}입니다.')
*코드설명
scores = list()
변수 scores는 list이다.
count = 0
while count < 7:
count += 1
point = input(f'{count}번째 심사위원 점수를 입력해 주세요:')
변수 count를 0으로 초기화해 주고,
count가 7이 될 때까지 +1씩 올라가며 input에 데이터를 받는다.
if point.replace('.','').isdecimal():
scores.append(float(point))
점수는 숫자만 입력받도록 하기 위해 replace()를 사용하여 소수점 기호를 제거한 후 isdecimal()로 숫자인지 확인한다.
숫자인 경우 float()를 사용하여 float 형으로 변환한 후 scores 리스트에 추가한다.
min = min(scores)
max = max(scores)
scores.remove(min)
scores.remove(max)
print(min, max)
score내부의 최대, 최솟값을 찾고 지워준다.
print(scores)
avg = sum(scores)/len(scores)
print(f'평균은 : {avg}입니다.')
최대, 최솟값이 제거된 점수를 보여주며, 그 점수의 평균을 보여준다.
728x90
'python' 카테고리의 다른 글
python 기초 10 (.txt / pickle 파일생성 및 쓰기 읽기) (2) | 2023.11.09 |
---|---|
python 기초 9 (리스트 내 for 문/ List Comprehension) (1) | 2023.11.09 |
python 기초 8 (boolean) (0) | 2023.11.09 |
python 기초 7 (반복문, 제어문) (1) | 2023.11.07 |
python 기초 6 (딕셔너리) (0) | 2023.11.07 |