제로베이스 데이터 취업 스쿨 - 5일차(6/6)(연산자실습)

수야·2023년 6월 6일
0

비교연산자(문자 비교)

문자와 아스키코드 변환

문자열 자체 비교


크다 작다는 안되고 같다 같지않다만 비교가능

실습

#알파벳을 입력하면 아스키코드를 출력하는 코드를 작성하자.
alpa=input('알파벳 입력 :')
print('{} : {}'.format(alpa, ord(alpa)))

#아스키코드를입력하면 문자를 출력하는 코드를 작성하자.
asci=int(input('아스키 코드 입력 :'))

print('{} : {}'.format(asci,chr(asci)))

[연습문제] 연산자(04)

#고도가 60m 올라갈 때 마다 기온이 0.8도 내려간다고 할 떄
#고도를 입력하면 기온이 출력되는 프로그램을 만들어보자.(지면온도 29도)
baseTemp=29
hight=int(input('고도 입력 :'))
step=60
down=0.8
pointTemp=baseTemp-(hight//step*down)
print(f'지면 온도: {baseTemp}')
print(f'고도 {hight}m의 기온: {pointTemp}')

왜 IF구문을 쓰는지 모르겠어...

#197개의 빵과 152개의 우유를 17명의 학생한테 동일하게 나눠 준다고 할 떄,
#한 명의 학생이 갖게 된ㄴ 빵과 우유 개수를 구하고 남는 빵과 우유 개수를 출력하자

bread=197
milk=152
student=17
oneStudentBread = bread // student
oneStudentMilk = milk // student
leftBread = bread % student
leftMilk = milk % student

print(f'학생 한명이 갖게되는 빵 개수 : {oneStudentBread}')
print(f'학생 한명이 갖게되는 우유 개수 : {oneStudentMilk}')
print(f'남는 빵 개수 : {leftBread}')
print(f'남는 우유 개수 : {leftMilk}')


변수를 무조건 앞에서 정의 해 줘야 뒤에서 써먹을 수 있다

[연습문제] 연산자(05)

#다음 내용을 참고해서 백신 접종 대상자를 구분하기 위한 프로그램을 만들어보자.
age=int(input('나이 입력:'))
if age<=19 or age>=65:
    yearEnd=int(input('출생 연도 끝자리 입력:'))
    if yearEnd==1:
        print('월요일 접종 가능!!')
    if yearEnd==2:
        print('화요일 접종 가능!!')
    if yearEnd==3:
        print('수요일 접종 가능!!')
    if yearEnd==4:
        print('목요일 접종 가능!!')
    if yearEnd==5:
        print('금요일 접종 가능!!')
    if yearEnd==6:
        print('토요일 접종 가능!!')
    if yearEnd==7:
        print('일요일 접종 가능!!')
    if yearEnd==8:
        print('월요일 접종 가능!!')
    if yearEnd==9:
        print('화요일 접종 가능!!')
    if yearEnd==0:
        print('수요일 접종 가능!!')
else: print('하반기 일정 확인')

😎파이썬 꿀팁(elif)

여러개의 if를 줄떄 if를 내려쓰는 방법말고 elif를 주는 방법이 있다.

#길이(mm)를 입력하면 inch로 환산하는 프로그램을 만들어보자.(1mm=0.039inch)
mm=int(input('길이 입력:'))
inch=mm*0.039
print('%d mm-> %.3finch'%(mm,inch))


profile
수야는 코린이에서 더 나아갈거야

3개의 댓글

comment-user-thumbnail
2023년 6월 7일

2023-06-07 복습 완료~

답글 달기
comment-user-thumbnail
2023년 6월 8일

2023-06-08
복습 완료

답글 달기
comment-user-thumbnail
2023년 6월 10일

2023-06-10
복습완료

답글 달기