[Python] 시험 결과 판별 / 구구단 / 운행 가능 횟수 / 누적 환자 수 / 최소 공배수

이소티·2023년 4월 21일

python

목록 보기
4/33

조건식

# 국어, 영어, 수학 점수를 입력하면 조건식을 이용해서 과목별 결과와 전체 결과를 출력
# (과목별 합격 점수 : 60점, 전체 합격 평균 점수 : 70점)

import operator

korScore = int(input('국어 점수 : '))
engScore = int(input('영어 점수 : '))
mathScore = int(input('수학 점수 : '))

avgScore = (korScore + engScore + mathScore) / 3 

print('국어 : PASS') if operator.ge(korScore,60) else print('국어 : FAIL')
print('영어 : PASS') if operator.ge(engScore,60) else print('영어 : FAIL')
print('수학 : PASS') if operator.ge(mathScore,60) else print('수학 : FAIL')
print('시험 : PASS') if operator.ge(avgScore,70) else print('시험 : FAIL')




반복문

# 1부터 100까지의 정수 중 2의 배수와 3의 배수를 구분해서 출력 (while문 사용)

n = 1
while n <101 :

    if n % 2 == 0 : 
        print('{}은 2의 배수이다.'.format(n))

    if n % 3 == 0 :
        print('{}은 3의 배수이다.'.format(n))
        
    n += 1

# while문을 사용해서 사용자가 입력한 구구단 출력

n = 1
gugudanNum = int(input('희망 구구단 입력 : '))

while n < 10 :

    print('{} * {} = {}'.format(gugudanNum,n,gugudanNum * n))

    n += 1

# 자동차 바퀴가 한 번 구를 때마다 0.15mm식 마모된다고 할 때
# 현재의 바퀴 두께가 30mm이고 최소 운행 가능 바퀴 두께가 20mm라고 할 때 앞으로 구를 수 있는 횟수는 ?

currentThickness = 30
count = 0
removeThickness = 0.15

while currentThickness >= 20 :
    count += 1
    currentThickness -= removeThickness

safeCount = count - 1
print('운행 가능 횟수 : {}'.format(safeCount))

# 하루에 독감으로 병원 방문 환자 수가 50명에서 100명 사이일 때
# 누적 독감 환자 수가 최초 10000명을 넘는 날짜는 ?

import random

sum = 0
date = 1
flag = True

while flag :
    patientCount = random.randint(50,100)
    sum += patientCount
    date += 1
    print('날짜 : {}\t 오늘 환자수 : {}\t 누적 환자수 : {}'.format(date,patientCount,sum))

    if sum > 10000 :
        flag = False

# 1부터 100까지의 정수 중 3과 7의 공배수와 최소 공배수를 출력

minNum = 0

for i in range(1,101) :
    if i % 3 != 0 or i % 7 != 0 :
        continue
    
    print('공배수 : {}'.format(i))

    if minNum == 0 :
        minNum = i 
    
else :
    print('최소 공배수 : {}'.format(minNum))
profile
데이터 관련 학습 일지

0개의 댓글