파이썬(3)
-
[나도코딩 파이썬 기본편] #11 모듈, 패키지 따라하기
1. 모듈 #정가 def price(people): print("{}명 가격은 {}원 입니다." .format(people, people * 10000)) #조조할인 def price_morning(people): print("{}명 조조 할인 가격은 {}원 입니다." .format(people, people * 6000)) #군인할인 def price_soldier(people): print("{}명 군인 할인 가격은 {}원 입니다." .format(people, people * 4000)) import theater_module theater_module.price(3) theater_module.price_morning(4) theater_module.price_soldier(2) from thea..
2022.02.03 -
[나도코딩 파이썬 기본편] #10 예외처리 따라하기
1. (에러에 대한) 예외처리 try: print("나누기 전용 계산기입니다.") nums = [] nums.append(int(input("첫 번째 숫자를 입력하세요 : "))) nums.append(int(input("두 번째 숫자를 입력하세요 : "))) nums.append(int(nums[0] / nums[1])) print("{} / {} = {}" .format(nums[0], nums[1], nums[2])) try: print("나누기 전용 계산기입니다.") num1 = int(input("첫 번째 숫자를 입력하세요 : ")) num2 = int(input("두 번째 숫자를 입력하세요 : ")) print("{} / {} = {}" .format(num1, num2, int(num1/nu..
2022.02.02 -
[나도코딩 파이썬 기본편] #9 클래스 Class 따라하기
1, 2. 클래스와 init class Unit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage print("{} 유닛이 생성되었습니다." .format(self.name)) print("체력 {}, 공격력 {}" .format(self.hp, self.damage)) marine = Unit("마린", 40, 5) tank = Unit("탱크", 150, 35) __init__ : 객체의 생성자 / self를 제외하고 객체(marine, tank)의 유닛(name, hp, damage)과 동일하게 만들어야 한다 3. 멤버변수 wraith1 = Unit("레이스", 80, 5) print("유..
2022.02.02