본문 바로가기

_Programming/Python

(11)
Error.-m pip install --upgrade pip 필요한 클래스들을 설치시 python의 pip를 업그레이드 해줘야 하는 경우들이 있다. 그래야만 해당 클래스를 가져다 사용할 수 있다. PIP 업그레이드 방법 cmd 창을 열고 아래 명령어를 입력한다. 다음과 같이 pip버전을 골라서 설치해준다. python -m pip install --upgrade pip
Basic.모듈과 패키지 모듈(Module) 필요한 것들이 부품처럼 잘 만들어져 있는 파일 필요에 맞게 부품을 가져다 쓰는 것처럼 사용자의 용도에 맞게 파일을 가져다 쓰면된다. 주의점은 import할 때 모듈 파일은 사용하고자 하는 파일과 같은 경로상에 존재하거나 library상에 존재해야 한다. # 기본 import import theater_module theater_module.price(3) theater_module.price_morning(3) theater_module.price_soldier(3) # import명이 길때는 as 이용하여 별칭사용 import theater_module as mv mv.price(3) mv.price_morning(3) mv.price_soldier(3) # module에 해당하는 ..
Basic.예외처리 예외처리 except 이용. err사용시 내제되어 있는 err의 내용이 출력됌. try: print("나누기 전용 계산기입니다.") nums = [] nums.append(int(input("첫 번째 숫자를 입력하세요 : "))) nums.append(int(input("첫 번째 숫자를 입력하세요 : "))) print("{0} / {1} = {2}".format(nums[0], nums[1], nums[2])) except ValueError: print("에러! 잘못된 값을 입력했쒀~~~") except ZeroDivisionError as err: print(err) except Exception as err: print("알 수 없는 에러가 발생하였습니다.") print(err) 에러 발생시키기 ..
Basic.클래스 현재까지 우리가 배워온대로 함수를 만들고 그에 따라 행동하는 무엇인가를 한 개씩 만들어 본다. # 마린 : 공격 유닛, 군인. 총을 쏠 수 있음 name = "마린" hp = 40 damage = 5 print("{0} 유닛이 생성되었습니다.".format(name)) print("체력 {0}, 공격력 {1}\n".format(hp, damage)) # 탱크 : 공격 유닛, 탱크. 포를 쏠 수 있는데, 일반모드 / 시즈 모드. tank_name = "탱크" tank_hp = 150 tank_damage = 35 print("{0} 유닛이 생성되었습니다.".format(tank_name)) print("체력 {0}, 공격력 {1}\n".format(tank_hp, tank_damage)) def attac..