0
running python3 testing.py...

sending input 22...

sending input 18...

checking for output "Too large!"...

my code couldn't pass the guessing game test, the test is sending 22 as a number to be guessed and 18 is the first guess number,and test thinks 18 is Too large or am I mistaken? anybody faced same problem?

while True:
    try:
        level = int(input("Level: "))
        break
    except ValueError:
        pass

while True:
    try:
        guess = int(input("Guess: "))
    except ValueError:
        pass
    else:
        if guess == level:
            print("Just right!")
            break
        elif guess > level:
            print("Too large!")
        else:
            print("Too small!")
3
  • if you dont share your code we have no idea what you are doing wrong. Please share your code (text not an image), and show the exact input and output you are running it with and what you are expecting it to output. we dont know what testing.py contains.
    – UpAndAdam
    Commented Feb 8 at 22:30
  • this code should pass the test, but I don't have any idea why it couldn't
    – Subhan SA
    Commented Feb 9 at 9:04
  • As @DinoCoderSaurus points out in his answer you are not following the spec, it should not pass the test. And you have not even demonstrated that it follows expected behavior for a manual input series.
    – UpAndAdam
    Commented Feb 9 at 14:28

1 Answer 1

2

Review the spec.

Prompts the user for a level,n. If the user does not input a positive integer, the program should prompt again.

Randomly generates an integer between 1 and n, inclusive, using the random module.

The program is not specified to guess the level. The program needs to generate a random number between 1 and level using the random module. That will be the number to guess.

4
  • why I have to randomly generate an integer when the code re prompt user until the user give an integer. the code is based on the specs that has been outlined by CS50P , I have trouble passing the testing phase
    – Subhan SA
    Commented Feb 9 at 13:32
  • The code is NOT following the specs that are DETAILED in the assignment. Not outlined, detailed. You can't pass the testing phase because the code isn't doing what it is supposed to do.
    – UpAndAdam
    Commented Feb 9 at 14:46
  • info added to answer Commented Feb 9 at 15:48
  • my bad, yeah I totally misunderstood , now all the pieces comes together, Thanks,
    – Subhan SA
    Commented Feb 9 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .