• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

# 파이썬 실전프로그래밍 1. 숫자맞추기 게임 질문 드립니다.

20.02.14 07:14 작성 조회수 213

1

안녕하세요. 남박사님 

다름이 아니라 숫자 맞추기 게임에 문의드립니다.

하단에  user_input = casting(input ("몇 일까요?")) 쓰셨는데

매개변수 msq를 바로 user_input = casting(input ("msq")) 안 쓰신 이유라도 있으신지 궁금합니다.

*실행은 결과는 똑같지만 혹시 어떤 실무적인 부분에서 어떤 차이가 있는지 궁금합니다. 또 한 

 1.user_input = casting(input ("몇 일까요?")) 

 2.user_input = casting(input ("msq")) 

두가지 중 어떠한 많이 쓰이는 방법이 어떤건지 궁금합니다.

아래 하단에 전체적인 코드를 삽입하였습니다. 

감사합니다.

def input_check(msqcastingint):
    while True:
        try:
            user_input = casting(input("몇 일까요?")) # Input은 항상 str로 받음.
            return user_input
        except:
            continue

 

# 숫자 맞추기 게임

import random
import os ## dos 화면까지 화면을 깨끗히 제일 상단에 오게 바꿔줌.

def input_check(msqcastingint):
    while True:
        try:
            user_input = casting(input(msq)) # Input은 항상 str로 받음.
            return user_input
        except:
            continue


chacne = 10
count = 0


number = random.randint(1,99)
os.system("cls"# dos 화면까지 화면을 깨끗히 제일 상단에 오게 바꿔줌.
print("1부터 99까지의 숫자를 10번 안에 맞춰 보세요.")



while count < chacne:
    count += 1
    user_input = input_check("몇 일까요? ")    

    if number == user_input:
        break
    
    elif user_input < number:
        print("{}보다 큰 숫자 입니다.".format(user_input))
        print("{}".format(" " * 60))
        print("{}".format("*" * 60))
        print("{}번의 기회를 남았습니다..".format(10-count))
        print("{}".format("*" * 60))
        print("{}".format(" " * 60))
        
    elif user_input > number: 
        print("{}보다 작은 숫자 입니다.".format(user_input))  
        print("{}".format(" " * 60))
        print("{}".format("*" * 60))
        print("{}번의 기회가 남았습니다.".format(10-count))
        print("{}".format("*" * 60))
        print("{}".format(" " * 60))


if user_input == number:
    print("성공! {}이 맞습니다.".format(number))
else:
    print("실패, 정답은 {} 입니다.",number)


답변 2

·

답변을 작성해보세요.

1

코드를 확인해보니 그렇게쓰시는게 맞습니다. 변수를 선언하고 사용하지 않은 제 실수를 짚어주셨습니다.^^;; 

0

남박사님. 답변 감사드립니다.