ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 아몬드봉봉 팀: 모각코 5주차 5회모임 결과 (22.08.08 / 월요일 / 21시 ~ 24시)
    카테고리 없음 2022. 8. 8. 23:57

    5-3. while

    customer = "토르"
    index = 5
    while index >=1:  
        print("{0},커피가 준비 되었습니다. {1} 번 남았어요".format(customer, index))
        index -= 1
        if index == 0:
            print("커피는 폐기처분되었습니다")


    #무한루프
    customer = "아이언맨"
    index = 1
    while True:
        print("{0},커피가 준비되었습니다. 호출 {1}회".format(customer, index))
        index +=1



    customer = "토르"
    person = "Unknown"

    while person !=customer :  #조건에 맞아야 while문을 탈출
        print("{0}, 커피가 준비되었습니다".format(customer))
        person = input("이름이 어떻게 되세요")
    #input으로 받는 이름이 토르가 아니면 계속 반복하고 토르면 while문을 탈출한다.
     
     
     
    5-4. continue와 break
    absent = [2, 5] #결석
    no_book = [7] #책이 없음
    for student in range(1, 11): #1,2,3,4,5,6,7,8,9,10
        if student in absent:
            continue    
            #continue는 위의 조건을 만족하면 밑의 문장을 실행하지 않고 다음 반복으로 진행
        elif student in no_book:
            print("오늘 수업 여기까지. {0}는 교무실로".format(student))
            break
            #break는 뒤에 반복값이 있어도 바로 반복문을 탈출
        print("{0},책을 읽어봐".format(student))

    5-5. 한 줄 for

    #출석번호가 1 2 3 4, 앞에 100을 붙이기로 함
    student = [1,2,3,4,5]
    print(student)
    student = [i+100 for i in student]
    #student 리스트에 있는 i를 불러오면서 거기에 있는 i에 100을 더해서 리스트로 바꿔서 student에 넣는다
    print(student)

    #학생 이름을 길이로 변환
    student = ["Iron man", "Thor", "I am groot"]
    student = [len(i) for i in student]
    #student 리스트에 있는 i를 불러오면서 그 i들의 문자열길이를 리스트로 바꿔서 student에 넣는다
    print(student)

    student = ["Iron man", "Thor", "I am groot"]
    student = [i.upper() for i in student]
    print(student)
    #student 리스트에 있는 i를 불러오면서 그 i들을 대문자로 변환하여 리스트로 student에 넣는다

    6-1. 함수

    def open_account():
        print("새로운 계좌가 생성되었습니다.") #함수는 호출할 때까지 실행이 되지않음

    open_account()#함수를 호출해서 위의 문장이 출력된다.

    6-2. 전달값과 반환값

    def open_account():
        print("새로운 계좌가 생성되었습니다.") #함수는 호출할 때까지 실행이 되지않음

    open_account()#함수를 호출해서 위의 문장이 출력된다.


    #함수에는 opne_account()처럼 전달하는 값이 없는 경우도 있고, 반환값을 받는 함수도 있음
    def deposit(balance, money):#(잔액, 입금받는 돈)
        print("입금이 완료되었습니다. 잔액은 {0}원입니다.".format(balance + money))
        return balance + money #return으로 값을 반환

    balance = 0 #잔액
    balance = deposit(balance, 1000) #deposit이라는 입금하는 함수를 호출하면서 현재 잔액과 입금받는돈을 입력
    #잔액과 입금받는 돈을 계산한 값을 return으로 받고 그 값을 balance에 저장
    print(balance)

    def withdraw(balance, money): #출금
        if balance >= money: #잔액이 출금하는 돈보다 많을때
            print("출금이 완료되었습니다. 잔액은 {0}원입니다.".format(balance - money))
            return balance - money
        else:  #출금하는 돈이 잔액보다 많을때
            print("출금이 완료되지 않았습니다. 잔액은 {0}원입니다.".format(balance))
            return balance

    balance = 0 #잔액
    balance = deposit(balance, 1000)
    balance = withdraw(balance, 2000) #잔액보다 출금하려는 돈이 크기 때문에 withdraw함수의 else에 있는 return값을 출력
    balance = withdraw(balance, 500)

    def withdraw_night(balance, money): #저녁에 출금
        commission = 100 #수수료 100원
        return commission, balance - money -commission

    commission, balance = withdraw_night(balance, 500) # 밤에 500원 출금
    print("수수료는 {0}원이고, 잔액은 {1}원입니다.".format(commission, balance))

    6-3. 기본값

    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="파이썬"): # age와 main_lang값을 전달받지 않으면 기본적으로 age에 17, main_lang에 파이썬을 넣는다
        print("이름 : {0}\t나이: {1}\t주 사용언어 : {2}".format(name,age,main_lang))

    profile("유재석", "20", "자바")
    profile("김태호")

     

Designed by Tistory.