class goods(object): #변하지 않는 상품 가격 설정 letsbe = 500 coke = 1600 poweraid = 2500 #초기화 def __init__(self, in_money): self.in_money = in_money return #금액과 상품가격 비교 def judge(self, in_money): if in_money < self.letsbe: print("금액이 상품가격보다 적습니다.") elif in_money < self.coke: print("레쓰비를 선택할 수 있습니다.") elif in_money < self.poweraid: print("레쓰비와 콜라를 선택할 수 있습니다.") else : print("모두 선택 가능합니다.") #반복문으로 계속 작동 되는것을 표현 while True: #클래스 사용 human = goods(0) #투입 금액을 정수형으로 변환 in_money = int(input("넣을 금액 입력 : ")) #최소 가격의 상품보다 금액이 적으면 if in_money < human.letsbe: print("금액이 부족합니다. 반횐됩니다.") #최소 가격 상품보다 금액이 많다면 else : #judge 메소드에 투입금액 전달 human.judge(in_money) select = int(input("어느것을 선택하시겠습니까? (1:레쓰비, 2:콜라 3:파워에이드 4:취소) : ")) if select == 1: print("레쓰비가 나옵니다. \n거스름돈 : "+ str(in_money-human.letsbe) +"원이 반환됩니다.") elif select == 2 and in_money>=human.coke: print("콜라가 나옵니다. \n거스름돈 : "+ str(in_money-human.coke) +"원이 반환됩니다.") elif select == 3 and in_money>=human.poweraid: print("파워에이드가 나옵니다. \n거스름돈 : "+ str(in_money-human.poweraid) +"원이 반환됩니다.") else : print("취소되었습니다.") #선택이 끝나면 while문 종료 break print("자판기를 이용해주셔서 감사합니다.")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question