python

·python
행멘 게임 단계별로 만들기 실습 (3)  *구현 내용 : while 반복문을 이용하여 while의 조건문이 false가 됐을 때 반복문을 멈추게 한다. while의 조건문이 false가 되는 경우는, 더이상 빈칸이 남아있지 않은 경우가 되어야한다.#Step 2import randomword_list = ["aardvark", "baboon", "camel"]chosen_word = random.choice(word_list)#테스트 코드print(f'Pssst, the solution is {chosen_word}.')blank = []for i in range(0, len(chosen_word)): i = "_" blank += i #빈칸이 모두 채워질 때까지 아래 코드 반복하기#초기값..
·python
행멘 게임 단계별로 만들기 실습 (2) *구현 내용 : range 함수를 이용하여 정답의 글자수만큼 리스트 속 요소를 정답 글자로 변환해주는 행위를 반복해준다.import randomword_list = ["aardvark", "baboon", "camel"]chosen_word = random.choice(word_list)#테스트 코드print(f'Pssst, the solution is {chosen_word}.')#1 문자열의 글자 수만큼 '_' 생성 -> 리스트 형식으로blank = []for i in range(0, len(chosen_word)): i = "_" blank += i#print(blank) = ['_','_',...,'_'] #입력값guess = input("G..
·python
행멘 게임 단계별로 만들기 실습 (1) *구현 내용 : for문을 사용하여 문자열의 알파벳을 하나씩 검사하고, 입력한 값과 문자열이 동일하거나 다르다면 특정 문구를 출력하도록 한다.word_list = ["aardvark", "baboon", "camel"]#1 word_list 에서 랜덤으로 하나를 지정chosen_word = random.choice(word_list)#2 입력값 (대문자를 입력해도 소문자로 변환해주는 함수 사용 필요)user_answer = input("Guess a letter: ").lower()#3 입력한 문자가 word_list에서 랜덤으로 지정된 단어에 존재하는지 체크 -> 있다면 Right, 없다면 Wrong 출력for letter in chosen_word: if le..
·python
Reeborg's World - Hurdle 4 내가 쓴 코드def turn_right(): turn_left() turn_left() turn_left()def turn_right_move(): turn_right() move()def jump(): if front_is_clear(): if right_is_clear(): if wall_in_front(): if wall_on_right(): move() else: turn_right_move() else: turn_rig..
·python
import randomletters = ['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']numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']..
·python
1) 리스트를 문자열로 변환하기 a = ['1','2','3','4']items = ""for i in a: items += i #결과 : 1234 1-a) .join() 함수 사용하기''.join(a)#결과: 1234 2) 문자열을 리스트로 변환하기a = '1234'a_list = []for i in a: a_list += iprint(a_list)#결과 : ['1','2','3','4'] 2-a) .split() 함수 사용하기a.split()#결과 : ['1','2','3','4']
·python
student_scores = input().split()for n in range(0, len(student_scores)): student_scores[n] = int(student_scores[n]) highest_score = 0for score in student_scores: if score > highest_score: highest_score = score# 처음 반복 때에는 highest_score가 0이기 때문에 당연히 score가 크다.# highest_score 값에 score 값을 저장해준다.
·python
중첩리스트 값 출력하기list1 = ["a","b","c","d"]list2 = ["e","f","g","h"]list = [list1, list2]#list 2의 첫번째 아이템 출력print(list[1][0])특정 위치에 보물 숨기기(특정 위치의 값을 'X'로 변환시키기// e.g. a1 => 1행 1열의 값을 X로 변환) line1 = ["⬜️","️⬜️","️⬜️"]line2 = ["⬜️","⬜️","️⬜️"]line3 = ["⬜️️","⬜️️","⬜️️"]#중첩 리스트map = [line1, line2, line3]print("Hiding your treasure! X marks the spot.")#입력값position = input() #position[0] = 문자, position[1] ..
단팥빵팥빵
'python' 카테고리의 글 목록 (2 Page)