This is just something I did in my free time. How can I improve my code as a beginner ?
- Is there an alternative to using
isalpha()
- What are other efficient ways to implement this program
- Suggestions for improving code structure
# The guess game
def guess_game():
done = False
quit = False
type_check = False
while not done:
num = input("enter num b/w 1 and 10: ")
quit = False
if num.isalpha():
if num == "quit":
while not quit:
quit_conf = str.lower(input("are you sure you want to quit - Y/n ?: "))
if quit_conf == "y":
exit()
elif quit_conf == "n":
quit = True
else:
print("invalid input")
else:
print("Invalid input")
type_check = False
elif num.isnumeric():
type_check = True
int_num = int(num)
else:
print("Invalid value")
type_check = False
# this is the answer
realno = 3
if type_check:
# checking if in range
if int_num < 1 or int_num > 10:
print("number out of range")
# checking num
elif int_num > realno:
print("number is higher")
elif int_num < realno:
print("number is lower")
else:
print("you win!")
done = True
return 0
guess_game()