티스토리 뷰
def clear_screen():
import os
if os.name in ('nt', 'dos'): # If Machine is running on Windows, use cls
os.system('cls')
else:
os.system('clear')
def guess_what(retry_count):
import random
random_number = random.randint(1,100)
print(random_number)
for chance in range(retry_count,0,-1):
print(f"You have {chance} attempts remaining to guess the number.")
guess_number = int(input("Make a guess: "))
if guess_number > random_number:
print(f"Too high.")
if chance > 1:
print("Guess again.")
elif guess_number < random_number:
print(f"Too low.")
if chance > 1:
print("Guess again.")
else:
print(f"You got it! The answer was {random_number}.")
return 0
print(f"You've run out of guesses, you lose. The number was {random_number}.")
def main():
clear_screen()
from title import logo
print(logo)
print("""
Welcome to the Numbr Guessing Game!
I'm thinking of a number between 1 and 100.
""")
difficulty = input("Choose a difficulty. Type 'easy' or 'hard':").lower()
if difficulty == 'easy' :
retry_count = 10
elif difficulty == 'hard':
retry_count = 5
elif difficulty == "":
retry_count = 5
else :
print("Invalid input. Bye.")
return 0
guess_what(retry_count)
main()
'Test > Python(20220101~)' 카테고리의 다른 글
Days14_숫자 업다운 게임 프로젝트 (리스트/딕셔너리 중첩 호출) (0) | 2022.01.22 |
---|---|
Day13_How to Debugging (0) | 2022.01.18 |
Days11_Black Jack, 21 (without comment) (0) | 2022.01.16 |
Days11_Black Jack, 21 (0) | 2022.01.16 |
Python 화면 지우기 (0) | 2022.01.15 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- vmware.powercli
- 읽어오기
- dp-2
- virt-sysprep
- 차집합
- 스토리지
- insert
- exadata
- powercli
- Join
- dezoomify
- powershell
- EXA
- storage
- 배열
- set()
- cloud-init
- 중복제거
- 변수화
- sysprep
- oracle
- dp-1
- 3par
- 대소문자
- fromkeys
- 정렬
- vmware
- artandculture
- 부동없이
- LIST
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함