숫자를 맞춰보세요

2710 단어 pythonbeginners
from random import randint

secret_number = randint(0, 10)  # guess number between 0 to 10 (including)
guess_count = 0

try:
    while True:
        user_number = int(input('Guess the number: '))
        guess_count += 1

        if user_number == secret_number:
            print('Correct')
            print('Your guess count:', guess_count)
            break
        elif user_number > secret_number:
            print('Your number is greater than the secret number.')
            continue
        elif user_number < secret_number:
            print('Your number is less than the secret number.')
            continue
        else:
            print('Invalid')
except ValueError:
    print('Please enter integer only.')

좋은 웹페이지 즐겨찾기