Python program that: Generates a random number between 1 and 100


I have tried everything i can still doesn't work. Please any help would be appreciated.
Please i have been able to allow it generate one hint, but i need it to generate 3 different hints the 3 different times the user presses 0 for the hint.
I have it give the hint even OR odd. i need it to give extra 2 hints.
Part 1:

  • Generates a random number between 1 and 100.
  • Allows the user 10 tries to guess what the number is.
  • Validates the user input (if user-input >100 or user-input<0) then this is invalid input and should not cost the user to lose any tries.
  • Gives feedback for each time the user makes a guess. The feedback tells the user whether the number entered is bigger, smaller, or equal to the number generated (and exits the program).
  • Tells the user if they lost after he/she consumes all the 10 tries. Gives the user 10 tries to guess the number. If the user exhausts the 10 ties. The user loses.

Part 2:

  • After 2 unsuccessful tries, the program should start offering hints for the users (by having the user input the number 0).
  • Each hint should be generated within a function of its own.
  • Each hint will cost the user two tries (the program should indicate this to the user)
  • The user is allowed a max of 3 hints only.
  • The program should randomly pick which hint it is going to use and display to the user.
    (example of a hint is : 1- The number is bigger than or equal the square of some X (X is an integer and is the largest integer square that is less than the user input))

Here is my program so far:

import randomguessesTaken = 0print('WELCOME! What is your name?')myName = input()number = random.randint(1, 100)print('Hello, ' + myName + ', I generated a number between 1 and 100.')unsuccessful_tries = 0hint_taken = 0while guessesTaken < 10:    if unsuccessful_tries > 1 and hint_taken<3:        print('Press 0 to get hint')        need_hint = int(input())        if need_hint == 0:            hint_taken += 1            guessesTaken += 1        if number%2==0:                 print('The Generated number is an EVEN number')        else:           print('The Generated number is an ODD number')    print('Take a guess.\t%d Attempts Left'%(10 - guessesTaken))    #10-guessTaken gives the number of tries left    guess = input()    guess = int(guess)    #validating the user's input    if guess >100 or guess<0:        continue    guessesTaken = guessesTaken + 1    if guess < number:        print('Your guess is too low.')    if guess > number:        print('Your guess is too high.')    if guess == number:        break    unsuccessful_tries+=1if guess == number:    guessesTaken = str(guessesTaken)    print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')if guess != number:    number = str(number)    print('Nope. The number I was thinking of was ' + number)

Best Solution

Let me nudge you towards solving part two:

  1. You're already keeping track of the user guesses with the guessesTaken variable

  2. A random 'Hint' can be simply randomly choosing through a list of pre-made hints ( if you had 5 pre-made hints, you could just choose a random number between 1-5, and select that one)

  3. 'Costing' the user two tries is as evaluating whether they have enough guesses to afford it ( i.e: if they are at guess number 9, they can't afford to give up 2 guesses), and then add two to the guessNumber if they accept a hint.

  4. You can evaluate the amount of hints taken with a counting variable, though given your parameters (they have to have two unsuccessful guesses to receive a hint, with a maximum of 3 hints total), they would not be able to have 3 hints.

This is the most exact answer i can give you, since you haven't provided any code for part 2 that isn't working or that you need help with.

loose example for point #2: choose a random function from a list:

my_list = [func_test_1, func_test_2, func_test_3]random.choice(my_list)()