반응형

언어/파이썬 19

[부트캠프] 블랙잭 게임 만들기 - 11일차

import random from replit import clear def deal_card(): """랜덤으로 카드 뽑기""" cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10] card = random.choice(cards) return card def calculate_score(cards): """카드 합계산""" if sum(cards) == 21 and len(cards) == 2: #두장의 카드합이 21이면 게임이 끝나는 조건 return 0 if 11 in cards and sum(cards) > 21: cards.remove(11) cards.append(1) return sum(cards) def compare(user_score,com_s..

언어/파이썬 2023.05.25

[부트캠프] 간단한 계산 프로그램 만들기 - 10일

✍코드 def add(n1, n2): return n1 + n2 def subtract(n1,n2): return n1- n2 def multiply(n1,n2): return n1 * n2 def divide(n1,n2): return n1/n2 #딕셔너리 안에 함수를 넣음 operation = { "+" : add, "-" : subtract, "*" : multiply, "/" : divide } # function = operation["*"] # function(2,3) def calculater(): num1 = float(input("첫번째 숫자를 입력하세요:")) flag = False while not flag: num2 = float(input("다음 숫자를 입력하세요:")) for s..

언어/파이썬 2023.05.22

[부트캠프]Dictionary 딕셔너리 -9일차

✍기본 문법 1.기본 딕셔너리 구조 키-값 dict = {"Bug": "bugvalue.", "Function": "function value."} 2.딕션너리 추가 , 생성, 초기화, 새로운 값추가 #딕션너리 추가 dict["abc"] = "abcccccc" #딕션너리 생성 dict_two ={} #딕션너리 초기화 dict ={} #딕션너리 새로운 값 추가 dict["Bug"] = "computer buy" 3. for 문을 통해서 값들을 받아 올때 #기초 #반복문 for key in dict: print(key) # 키값 print(dict[key]) #키에 해당하는 밸류값 #심화 #기존의 딕셔너리를 활용해서 새 딕셔너리를 만들때 for문을 이용 for student in student_scores:..

언어/파이썬 2023.05.17

[부트캠프] shift를 이용한 암호화 복호화 코드 8일차

👇알파벳을 이용한 암호화 복호화 코드 alphabet = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ] def caesar(start_text, shift_amount, cipher_direction): end_text = "" #decode일때만 -1 if cipher_direction..

언어/파이썬 2023.05.09

[부트캠프] for 과 while 반복문 - 6일차

for문 def turn_right(): turn_left() turn_left() turn_left() def jump(): move() turn_left() move() turn_right() move() turn_right() move() turn_left() #6번 반복하기 for step in range(6): jump() while문 안에 if문 쓰기 def turn_right(): turn_left() turn_left() turn_left() #무한 루프를 방지하기 위해 벽부터 찾는다 while front_is_clear(): move() turn_left() while not at_goal(): #오른쪽벽에 없으면 if right_is_clear(): turn_right() move() ..

언어/파이썬 2023.05.05

[부트캠프] random 함수와 배열 활용

👇코드 #ascii art에서 참고 rock = ''' _______ ---' ____) (_____) (_____) (____) ---.__(___) ''' paper = ''' _______ ---' ____)____ ______) _______) _______) ---.__________) ''' scissors = ''' _______ ---' ____)____ ______) __________) (____) ---.__(___) ''' #Write your code below this line import random #먼저 위의 코드들을 배열에 넣는다 img = [rock, paper, scissors] MyTrun = int(input("type 0 for rock, 1 for paper, ..

언어/파이썬 2023.05.01

[부트캠프]f-String 과 간단계산 - 2일

print("Welcome to the tip calculator") total = float(input("What was the total bill? $")) tip = float(input("What percentage tip would you like to give? 10, 12 or 15?")) people = int(input("How many people to split the bill?")) #팁과 전체 금액 다시 계산 total = total + (total*(tip*0.01)) #소수점 두자리가 0이 표시되도록 result = "{:.2f}".format(round((total/people),2)) print(f"Each person should pay:{result}")

언어/파이썬 2023.04.28
반응형