views:

111

answers:

4

Here is the Pseudocode

  1. Print instructions to the user
  2. Start with the variables high = 1000, low = 1, and tries = 1
  3. While high is greater than low
  4. Guess the average of high and low
  5. Ask the user to respond to the guess
  6. Handle the four possible outcomes:
    • If the guess was right, print a message that tries guesses were required and quit the program
    • If the guess was too high, print a message that says “I will guess lower.”
    • If the guess was too low, print a message that says “I will guess higher.”
    • If the user entered an incorrect value, print out the instructions again.

I don't even know where to begin.

A: 

You don't say if this is Python 2 or 3. The following should be good for recent versions of 2; I'm not familiar with 3, but it will probably at least get you started there too. Seeing as how this is homework, I'm just going to recommend some things for you to research.

  • You'll want to get the guesses and check them in a loop. I recommend looking up the while loop.
  • To get the user inputs, try raw_input.
  • To output messages, look up print.
  • Use if for checking the user's responses.
GreenMatt
A: 

You begin with point one:

print "instructions to the user"

(just change the string to be more informative, that's not a programming problem!-), then continue with point two (three assignments, just like your homework assignment says), then with point three:

while high > low:

There -- that's half your work already (points 1-3 out of 6). What's giving you problems beyond that? Do you know what average means, so (say) guess = (high + low) // 2 is understandable to you, or what? That's all you need for point 4! Do you know how to ask the user a question and get their response? Look up input and raw_input... OK, I've covered the first five of the six points, surely you can at least "get started" now!-)

Alex Martelli
Thank you so much :) All the answers here have helped.
Jostlyn Walton
A: 

Ok, this isn't the answer but you need to look at the program:

  1. Print out instructions.
  2. Make a random number or a use your own. (For rand numbers you need to use a modulus divide trick)
  3. Probably using a while loop: check if the number guessed is higher or lower or equal
  4. In case of higher print higher, in case of lower print lower, in case of equal break or call exit (probably breaking will do fine).

Pseudo Code:

print "intructions"
thenumber = rand() % 1000+1
while (true)
    getInput(guess);
    if (guess > thenumber)
        print "Guess lower"
    else if (guess < thenumber)
        print "Guess higher")
    else
        exit //or break.

Just pseudo code though.

thyrgle
+2  A: 

Here's where you begin. Insert the specifications as documentation, then do one at a time, testing along the way.

# Print instructions to the user
### 'print "xyz"' will output the xyz text.

# Start with the variables high = 1000, low = 1, and tries = 1
### You can set a variable with 'abc = 1'.

# While high is greater than low
### Python has a while statement and you can use something like 'while x > 7:'.
### Conditions like 'x > 7', 'guess == number' can also be used in `ifs` below.

    # Guess the average of high and low
    ### The average of two numbers is (x + y) / 2.

    # Ask the user to respond to the guess
    ### Python (at least 2.7) has a 'raw_input' for this, NOT 'input'.

    # If the guess was right, print a message that tries guesses were required
    # and quit the program
    ### Look at the 'if' statement for this and all the ones below.

    # If the guess was too high, print a message that says “I will guess lower.”
    # If the guess was too low, print a message that says “I will guess higher.”
    # If the user entered an incorrect value, print out the instructions again.

I've also added a small comment detailing what language elements you should look in to for each section.

paxdiablo
Thank you, it was very helpful :)
Jostlyn Walton