I started learning Python and wrote my first program. This is a console game based on guessing the number. Can you take a look and tell me if I'm doing it right or give me any advice? Here is the code: https://github.com/theriseq/GuessTheNumber
Is it a good way of doing this or can I simplify it?
Thank you.
main.py
from can_convert import check
import random
welcome_msg = """Welcome to GuessTheNumber Game!
I\'m thinking of a number between 1 and 100.
Can you guess this number?
[?] Type \'pass\' to exit game.
"""
print(welcome_msg)
number_to_guess = random.randrange(1, 101)
attemps = 0
while True:
user_inp = str(input("Your choice: "))
if user_inp != "pass":
if check(user_inp):
attemps += 1
# print('is int')
if int(user_inp) < number_to_guess:
print("Your guess is too small.")
elif int(user_inp) > number_to_guess:
print("Your guess is too high.")
else:
print("Correct! You won the game!")
print(f"Attemps: {attemps}")
break
else:
print('Enter numbers only!')
else:
break
can_convert.py
def check(to_check):
try:
int(to_check)
return True
except ValueError:
return False