Program that asks the user to guess generated number between 1 and 9. If player guessed too low, too high or equal there will be a message saying so. Program only finish when player types 'exit'.
I've created three functions.
import random
#function that creates a random number in between 1 and 9 inclusive
def number_generation():
computer_number=random.randint(1,9)
return computer_number
print(number_generation())
#function that asks the player to input number between 1 and 9
def player_number():
player_num=input('Digit your guess between 1 and 9\n')
return player_num
def guessing_game():
w_answers=0
r_answers=0
cpu_guess=int(number_generation())
player_guess=player_number()
while player_guess!='exit':
if int(player_guess)>cpu_guess:
print('You have guessed to high')
w_answers+=1
elif int(player_guess)<cpu_guess:
print('You have guessed to low')
w_answers+=1
else:
print('You have guessed the correct number')
r_answers+=1
return w_answers,r_answers
print(guessing_game())
It prints forever your guess is too low..
player_input- Nickcpu_guessto know what randomly generated number is. - Austin