Python Basic_연산자

jaam._.mini·2023년 11월 5일
0

📒Python 기초 수학

목록 보기
3/46

아직은 따라가기에 급급하지만..!
다음주 쯤에는 혼자 수식을 완성할 수 있겠지!

오늘의 목차

  • 연산자 기본
  • 나머지 & 몫
  • 거듭제곱/제곱근
  • 복합 연산자
  • 비교 연산자
  • 논리 연산자

📌연산자 기본

  • 산술 : +, -, *, /, %(나머지), //(몫), **(제곱승)
  • 할당 : = += -+ *= /= %=
  • 비교 : > >= < <= == !=
  • 논리 : and or not
Q.국어(85), 영어(90), 수학(95) 점수를 입력하고 합계를 출력

korea = int(input('국어 점수 : '))
english = int(input('영어 점수 : '))
math = int(input('수학 점수 : '))
total = korea+english+math

print('국어 점수 {}'.format(korea))
print('영어 점수 {}'.format(english))
print('수학 점수 {}'.format(math))
print ('합계 {}'.format(total))



📌나머지 & 몫 _ divmod() 함수

num1 = 10
num2 = 3
result = divmod(num1, num2)
print('result : {}'.format(result))
print('몫 : {}'.format(result[0]))
print('나머지 : {}'.format(result[1]))
Q.학급 전체 학생 수 25, 한 모둠에 속하는 학생수 4, 전체 모둠수 & 남는 학생수 출력하라

#1번 풀이 유형
allStudent = int(input('전체 학생수 : '))
studentGroup = int(input('모둠 학생수 : '))
group = allStudent//studentGroup #전체 모둠수 몫
over = allStudent%studentGroup #나머지

print('전체 학생수 : {}'.format(allStudent))
print('모둠 학생수 : {}'.format(studentGroup))
print('모둠수 : {}'.format(group))
print('남는 학생수 : {}'.format(over))

#2번 풀이 유형
allStudent = int(input('전체 학생수 : '))
studentGroup = int(input('모둠 학생수 : '))

result = divmod(allStudent, studentGroup)

print('전체 학생수 : {}'.format(allStudent))
print('모둠 학생수 : {}'.format(studentGroup))
print('모둠수 : {}'.format(result[0]))
print('남는 학생수 : {}'.format(result[1]))



📌거듭제곱/제곱근

📍제곱근 : n**(1/m)

result = 2**(1/3)
print ('2의 3제곱근 %f' % result)

📍거듭제곱 _ pow() 함수

print('2의 3제곱근 %f' math.pow(2,3))

📍거듭제곱 _ sqrt() 함수

print('3dml wprhqrms %f' math.sqrt(3))

⭐ 예제

Q. 첫달 200월, 매월 이전달의 2배 인상. 12개월째 되는 달?

firstMonthMoney = 200
after12Month = ((firstMonthMoney * 0.01)**12)*100

#1번 풀이
print('12개월 후 용돈 :  %.f 원' % after12Month)
-> 409600원

#2번 풀이
print('12개월 후 용돈 : {}'.format(after12Month)
-> 409600.0

#3번 풀이
after12Month = int(after12Month)
srtResult = format(after12Month, ',')
print(strResult, '원')
-> 409,600원


📌복합 연산자

Q. 누적 강수량?

rainAmount = 0
totalRainAmount = 0
totalRainAmount += 30
print('1월 누적강수량 : ' {}mm.format(totalRainAmnt)


📌비교 연산자

num! = 10; num2 = 5
result = num1 < num2
print('num < num2:{]'.format(result))
-> False


📌논리 연산자

age = int(input('나이 입력 : '))
vaccine = (age < 20) or (age >= 65)
print ('age : {}, vaccine : {}'.format(age, vaccine))

# 제로베이스 데이터 취업 스쿨
# Daily study note
profile
비전공자의 데이터 공부법

0개의 댓글