산술연산자 (거듭제곱)
# 첫 달에 용돈 200원을 받고 매월 이전 달의 2배씩 인상
# 12개월째 되는 달에는 얼마의 용돈을 받을 수 있을까?
firstMonthMoney = 200
after12Month = 200*(2**11)
after12MonthFormated = format(after12Month,',') #str형식으로 바뀜
print('12개월 후 용돈 : %s원' % after12MonthFormated)
비교연산자(숫자 비교)
# 최대 전장 길이가 5200mm이고 최대 전폭 길이가 1985mm일 때
# 자동차의 전장과 전폭을 입력하면 자동차 기계 세차 가능 여부를 출력하는 코드 작성
maxLength = 5200
maxWidth = 1985
myCarLength = int(input('전장 길이 입력 : '))
myCarWidth = int(input('전폭 길이 입력 : '))
print('전장 가능 여부 : {}'.format(myCarLength <= maxLength))
print('전폭 가능 여부 : {}'.format(myCarWidth <= maxWidth))
비교연산자(문자 비교)
# 아이디와 패스워드를 입력한 후 비교 결과를 출력
systemID = 'administrator@gmail.com'
sysoutPW = '123456789'
userInputID = input('아이디 입력 : ')
userInputPw = input('비밀번호 입력 : ')
print('아이디 비교 결과 : {}'.format(systemID == userInputID))
print('비밀번호 비교 결과 : {}'.format(sysoutPW == userInputPw))
논리연산자
# 국어, 영어, 수학 점수를 입력하고 평균이 70점 이상이면 True를 출력
korScore = int(input('국어 점수 : '))
engScore = int(input('영어 점수 : '))
mathScore = int(input('수학 점수 : '))
avgScore = (korScore + engScore + mathScore) / 3
if korScore >= 60 and engScore >= 60 and mathScore >= 60 :
pass_result = True
else :
pass_result = False
if (pass_result == True) and (avgScore >= 70) :
result = True
else :
result = False
print('평균 : {}, 결과 :{}'.format(avgScore, True if avgScore >=70 else False))
print('국어 : {}, 결과 : {}'.format(korScore, True if korScore >= 60 else False))
print('영어 : {}, 결과 : {}'.format(engScore, True if engScore >= 60 else False))
print('수학 : {}, 결과 : {}'.format(mathScore, True if mathScore >= 60 else False))
print('과락 결과 :{}'.format(pass_result))
print('최종 결과 : {}'.format(result))
operator 모듈
# random과 operator 모듈을 사용해서 10부터 100사이의 난수 중 십의 자리와 일의 자리가 각각 3의 배수인지 판단
import random
import operator
rInt = random.randint(10,100)
num10 = operator.floordiv(rInt,10)
num1 = operator.mod(rInt,10)
print('난수 : {}'.format(rInt))
print('십의 자리 : {}'.format(num10))
print('일의 자리 : {}'.format(num1))
print('십의 자리는 3의 배수이다 :{}'.format(operator.mod(num10,3) == 0))
print('일의 자리는 3의 배수이다 :{}'.format(operator.mod(num1,3) == 0))