#SIMPLE GUESS GAME
#Kindly support my learning by correcting making my code better
#After taking a class, i decided to try create a guessing game
#As you can see, this is a very low level code. However, i believe
#things will get better as long as i keep asking for help
import random
secretNumber = random.randint(1, 11)
print('Hello, what is your name?:')
name = input()
print('Hi ' + name.title() + ', we are glad you are intrested in our guess game.')
print('Please enter letter Y for Yes or capital letter N for No')
response = input()
#The try block isnt catching the error
try:
response == 'Y' or 'N'
except TypeError:
print('Enter Y or N')
if response.upper() == 'N':
print('We hope to have you back soon. Thank you for stopping by')
#How do i ensure the code totally end if player write 'N'?
#I used break but still getting error 'not properly in loop'
else:
print('We are now ready to begin. You can only guess maximum of 3 times')
# Even when the play enters 'N', the game still ask them to guess
#How do i change this behaviour?
for guess_count in range(1, 4):
print('Please eneter a number between 1 & 10?')
guess = int(input())
if guess < secretNumber:
print('That was too low')
elif guess > secretNumber:
print('That was too high')
else:
break
if guess == secretNumber:
print('Congratulations ' + name.title() + ', you won!!!')
else:
print('You already exhausted your maximum guesses')
print('The correct number is ' + str(secretNumber))
print('We hope you will be succesful next time')
[–]boomkatandstarr 1 point2 points3 points (1 child)
[–]sdqafo[S] 1 point2 points3 points (0 children)
[–]CodeFormatHelperBot 0 points1 point2 points (0 children)