나도코딩 파이썬 코딩 무료 강의를 듣고 파이썬 문법의 전반적인 것들을 정리하면서 복습해보았다.
weather = input("오늘 날씨는 어때요?")
if weather == "비" or weather == "눈":
print("우산을 챙기세요")
elif weather == "미세먼지":
print("마스크를 챙기세요")
else:
print("준비물 필요 없어요")
for waiting_no in range(1, 6): # 1, 2, 3, 4, 5
print("대기번호 : {0}".format(waiting_no))
starbucks = ["아이언맨", "토르", "캡틴아메리카"]
for customer in starbucks:
print("{0}손님, 주문하신 커피가 나왔습니다.".format(customer))
custmer = "토르"
index = 5
while index >= 1:
print("{0}손님, 커피가 주문되었습니다. {1}번 남았어요.".format(custmer, index))
index -= 1
if index == 0:
print("커피는 폐기처분되었습니다.")
customer = "아이언맨"
index = 1
while True:
print("{0}손님, 커피가 주문되었습니다. 호출 {1}회".format(custmer, index))
index += 1 #무한루프
absent = [2, 5] # 결석
no_book = [7]
for student in range(1, 11): # 1 ~ 10 출석번호
if student in absent:
continue
elif student in no_book:
print("오늘 수업 여기까지. {0}은 교무실로 따라와".format(student))
break
print("{0}아 책을 읽어봐".format(student))
# 출석번호가 1, 2, 3, 4 ... 앞에 100을 붙이기로 함 -> 101, 102, 103, 104 ...
students = [1, 2, 3, 4, 5]
print(students)
students = [i + 100 for i in students]
print(students)
def open_acount():
print("새로운 계좌가 생성되었습니다.")
open_acount()
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 withdraw_night(balance, money): # 수수료 함수
commision = 100
return commision, balance-money-commision
balance = 0
balance = deposit(balance, 1000) # 1000원 입금
balance = withdraw(balance, 500) # 500원 출금
commision, balance = withdraw_night(balance, 100) # 100원 출금, 수수료 100원
print("수수료는 {0}원이며 잔액은 {1}원입니다".format(commision, balance))
def profile(name, age, *language): # 가변인자 (서로 다른갯수의 값을 넣어줄때 사용)
print("이름 : {0}\t나이 : {1}".format(name, age), end=" ")
for lang in language:
print(lang, end=" ")
print()
profile("제임스", 36, "Python", "Java", "C", "C#", "C++", "JavaScript")
profile("존", 31, "Kotlin", "Swift")
gun = 10
def checkpoint(soldiers):
global gun # 전역공간에 있는 gun 이용
gun = gun - soldiers
print("[함수 내] 남은 총 : {0}".format(gun))
def checkpoint_ret(gun, soldiers):
gun = gun - soldiers
print("[함수 내] 남은 총 : {0}".format(gun))
return gun
print("전체 총 : {0}".format(gun))
checkpoint(2)
gun = checkpoint_ret(gun, 2)
print("남은 총 : {0}".format(gun))