목록IT/Python (32)
개발로그필름
# while customer = "토르" index = 5 while index >= 1: print("{0}, 커피가 준비 되었습니다. {1}번 남았어요.".format(customer, index)) index -= 1 if index == 0: print("커피는 폐기처분 되었습니다.") # 무한루프 customer = "아이언맨" index = 10 while True: print("{0}, 커피가 준비되었습니다. 호출 {1}회".format(customer, index)) index += 1 customer = "토르" person = "Unknown" while person != customer : print("{0}, 커피가 준비 되었습니다.".format(customer)) person ..
def open_accout(): print("새로운 계좌가 생성되었습니다.") def deposit(balance, money): # 입금 print("입금이 완료되었습니다. 잔액은 {0}원 입니다.".format(balance + money)) return balance + money def withdraw(balance, money): # 출금 if balance >= money: # 잔액이 출금보다 많으면 print("출금이 완료되었습니다. 잔액은 {0}원 입니다.".format(balance - money)) return balance - money else: print("출금이 완료되지 않았습니다. 잔액은 {0}원 입니다.".format(balance)) return balance def wi..
# 기본값 def profile(name, age, main_lang): print("이름 : {0}\t나이 : {1}\t주 사용 언어: {2}".format(name, age, main_lang)) profile("유재석", 20, "파이썬") profile("김태호", 25, "자바") # 같은 학교 같은 학년 같은 반 같은 수업. def profile(name, age=17, main_lang="파이썬"): print("이름 : {0}\t나이 : {1}\t주 사용 언어 : {2}".format(name, age, main_lang)) profile("유재석") profile("김태호") # 키워드 값 def profile(name, age, main_lang): print(name, age, mai..
from random import * print(random()) # 0.0 ~ 1.0 미만의 임의의 값 생성 print(random() * 10) # 0.0 ~ 10.0 미만의 임의의 값 생성 print(int(random() * 10)) # 0 ~ 10 미만의 임의의 값 생성 print(int(random() * 10)) # 0 ~ 10 미만의 임의의 값 생성 print(int(random() * 10)) # 0 ~ 10 미만의 임의의 값 생성 print(int(random() * 10) + 1) # 1 ~ 10 이하의 임의의 값 생성 print(int(random() * 10) + 1) # 1 ~ 10 이하의 임의의 값 생성 print(int(random() * 10) + 1) # 1 ~ 10 이하..
print("a" + "b") # ab print("a", "b") # a b # 방법 1 print("나는 %d살입니다." % 20) print("나는 %s을 좋아해요." % "파이썬") print("Apple은 %c로 시작해요." % "A") # %s print("나는 %s살입니다." % 20) print("나는 %s색과 %s색을 좋아해요." % ("파란", "빨간")) # 방법 2 print("나는 {}살 입니다.".format(20)) print("나는 {}색과 {}색을 좋아해요.".format("파란", "빨간")) print("나는 {0}색과 {1}색을 좋아해요.".format("파란", "빨간")) print("나는 {1}색과 {0}색을 좋아해요.".format("파란", "빨간")) # 방..
# \n : 줄바꿈 print("백문이 불여일견\n백견이 불여일타") # \" \' : 문장 내에서 따옴표 # 저는 "나도코딩" 입니다. print("저는 '나도코딩'입니다.") print("저는 \'나도코딩\'입니다.") # \\ : 문장 내에서 \ print("C:\\Users\\user\\Desktop\\PythonWorkspace>") # \r : 커서를 맨 앞으로 이동 print("Red apple\rPine") # Pineapple # \b : 백스페이스 (한 글자 삭제) print("Redd\bApple") # RedApple # \t : 탭 print("Red\tApple") # Red Apple
# 리스트 [] # 지하철 칸별로 10명, 20명, 30명 subway1 = 10 subway2 = 20 subway3 = 30 subway = [10, 20, 30] subway = ["유재석", "조세호", "박명수"] # 조세호씨가 몇 번째 칸에 타고 있는가? print(subway.index("조세호")) # 1 # 하하씨가 다음 정류장에서 다음 칸에 탐 subway.append("하하") # 정형돈씨를 유재석 / 조세호 사이에 태워봄 subway.insert(1, "정형돈") # 지하철에 있는 사람을 한 명씩 뒤에서 꺼냄 subway.pop() # 같은 이름의 사람이 몇 명 있는지 확인 subway.append("유재석") subway.count("유재석") # 2 # 정렬도 가능 num_lis..
# def profile(name, age, lang1, lang2, lang3, lang4, lang5): # print("이름 : {0}\t나이 : {1}\t".format(name, age), end=" ") # print(lang1, lang2, lang3, lang4, lang5) def profile(name, age, *language): print("이름 : {0}\t나이 : {1}\t".format(name, age), end=" ") for lang in language: print(lang, end=" ") print() profile("유재석", 20, "Python", "Java", "C", "C++", "C#", "JavaScript") profile("김태호", 25, "Kot..