-4

I made a simple number guessing Game and it works perfectly fine, but I want to add something that says "The Number you have entered is too high/ low", because when I type in 100 as my upper bound it is much too difficult to guess the number.

import random

while True:
    flag = True
    while flag:
        num = input('Enter an upper bound: ')

        if num.isdigit():
            print("Let's Play!")
            num = int(num)
            flag = False
        else:
            print('Invalid input! Try again!')

    secret = random.randint(1,num)

    guess = None
    count = 1

    while guess != secret:
        guess = input('Please enter a number between 1 and ' + str(num) + ": " )
        if guess.isdigit():
            guess = int(guess)
        if guess == secret:
            print('Right! You have won!')
        else:
            print('Try again!')
            count += 1

    print('You needed', count, 'guess(es) ')
1
  • 3
    What have you tried? What specifically do you need help with? Have you tried using < and >? Commented Aug 29, 2019 at 18:49

1 Answer 1

2

Alright, I'm not gonna solve it for you, but I'll give you a hint. This seems like a homework problem, so it would be unethical of me to provide you with a solution.

 else:
            print('Try again!')
            count += 1

Look at this else statement here. What is the purpose of this else statement? To tell the user they got the guess wrong.

Think about how you can put an if/else condition inside this else condition, to tell the user if their input is too high, or too low.

Sign up to request clarification or add additional context in comments.

1 Comment

I fixed it now, but still thank you for taking your time to help me :) And it wasn't a Homework btw ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.