티스토리 뷰
For & While loops
IF/Else
Lists
Strings
Range
Modules
총 망라하여 생각할 필요 있음
https://drive.google.com/file/d/14SDAxEl7ehqtyvWceCrbtlvzQsldPxSa/view?usp=sharing
* My first code
word_list = ["aardvark", "baboon", "camel"]
#TODO-1 - Randomly choose a word from the word_list and assign it to a variable called chosen_word.
#TODO-2 - Ask the user to guess a letter and assign their answer to a variable called guess. Make guess lowercase.
#TODO-3 - Check if the letter the user guessed (guess) is one of the letters in the chosen_word.
#------------------------------------------------------------------------------------------------------------------
stages = ['''
+---+
| |
O |
/|\ |
/ \ |
|
=========
''', '''
+---+
| |
O |
/|\ |
/ |
|
=========
''', '''
+---+
| |
O |
/|\ |
|
|
=========
''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========
''', '''
+---+
| |
O |
|
|
|
=========
''', '''
+---+
| |
|
|
|
|
=========
''']
#TODO-1 - Randomly choose a word from the word_list and assign it to a variable called chosen_word.
import random
#chosen_word = word_list[random.randint(0,len(word_list)-1)]
chosen_word=random.choice(word_list)
print(f'Pssst, the solution is {chosen_word}.')
display=[]
for letter in chosen_word:
#for _ in chosen_word:
#for _ in range(len(chosn_word))
display+="_"
print(display)
#print(f"{word_list[chosen_word]}")
# count = len(chosen_word
# while (count>0):
end_of_game = False
lives = 6
while not end_of_game:
#TODO-2 - Ask the user to guess a letter and assign their answer to a variable called guess. Make guess lowercase.
did_match = False
print(stages[lives])
guess=input("Guess a letter : ").lower()
#print(guess)
#TODO-3 - Check if the letter the user guessed (guess) is one of the letters in the chosen_word.
for point in range(len(chosen_word)):
#for point in range(0,len(chosen_word)):
#for letter in chosen_word:
if guess == chosen_word[point]:
display[point] = guess
did_match = True
if did_match == False:
#if guess not in chosen_word:
lives-=1
if lives == 0:
end_of_game = True
print("You lose.")
print(f"The solution is : {chosen_word}")
print(display)
if "_" not in display:
end_of_game = True
print("You win.")
'Test > Python(20220101~)' 카테고리의 다른 글
Day8_입력값이 있는 함수 (0) | 2022.01.09 |
---|---|
Day7_Hangman Game2 (0) | 2022.01.08 |
Day6_미로탈출 (0) | 2022.01.07 |
Day6_While loop (0) | 2022.01.07 |
Day6_Style Guide for Python Code (0) | 2022.01.07 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 차집합
- 배열
- Join
- fromkeys
- 대소문자
- storage
- dp-1
- virt-sysprep
- dp-2
- powercli
- powershell
- oracle
- EXA
- sysprep
- LIST
- cloud-init
- 스토리지
- 부동없이
- insert
- artandculture
- 변수화
- exadata
- 정렬
- vmware
- 중복제거
- dezoomify
- 3par
- 읽어오기
- vmware.powercli
- set()
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
글 보관함