Note that there are some explanatory texts on larger screens.

plurals
  1. POReverse game python
    primarykey
    data
    text
    <p>Hello i know this is asked a couple of times already but i couldnt find the answer. The question is about the reverse guess my number game. The code executes the program but not in a "humanlike" way. If the number is 50 and it guesses 20 it responds as higher, the computer says 30 for example, it gets the response lower it guesses 15. How do i solve this? The exercise comes from: Python for the absolute beginner. Can someone help me? In a simple way please because otherwise i skip things in the book. I think you can see what i know and what not by seeing the code. Please help me...</p> <p>Code:</p> <pre><code>#Guess My Number # #The computer picks a random number between 1 and 100 #The playes tries to guess it and the coputer lets #the player know if the guess is too high, too low #or right on the money print ("\t// // // // // // // // // //") print ("\tWelcome to 'Guess My Number'!") print ("\tComputer VS Human") print ("\t// // // // // // // // // //") name = input("What's your name?") print ("Hello,", name) print ("\nOkay, think of a number between 1 and 100.") print ("I'll try to guess it within 10 attemps.") import random #set the initial values the_number = int(input("Please type in the number to guess:")) tries = 0 max_tries = 10 guess = random.randint(1, 100) #guessing loop while guess != the_number and tries &lt; max_tries: print("Is it", guess,"?") tries += 1 if guess &gt; the_number and tries &lt; max_tries: print ("It's lower") guess = random.randint(1, guess) elif guess &lt; the_number and tries &lt; max_tries: print ("It's higher") guess = random.randint(guess, 100) elif guess == the_number and tries &lt; max_tries: print("Woohoo, you guessed it!") break else: print("HAHA you silly computer it was", the_number,"!") input ("\n\nTo exit, press enter key.") </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload