Jump to content

Python: How To Make Shell Wait After Command?

piggykid1

So I learned how to make a Python Guessing Game thanks to this guy

 

I have done this in an API, but I forgot how to oops haha.

 

If you run this code, after 10 guesses (how many guesses you have) or get it right it exits the shell so if you got it right on your last guess you don't know if you did.

 

Hopefully that makes since I can make a video if my text description doesn't help.

 

Thanks!

 

P.S. You can paste it into Notepad ++ save it was a .py file then click run at the top :)

Link to comment
Share on other sites

Link to post
Share on other sites

import randomimport msvcrt as mnumber = random.randint(1, 1000)guesses = 0while guesses < 10:    guess = int(raw_input("Enter an integer from 1 to 1,000: "))    guesses +=1    print "this is your %d guess" %guesses    if guess < number:        print "guess is low"    elif guess > number:        print "guess is high"    elif guess == number:        breakif guess == number:    guesses = str(guesses)    print "You guess it in : ", guesses + " guesses"if guess == number:    guesses = str(guesses)    print "You guess it in : ", guesses + " guesses"if guess != number:    number = str(number)    print "The secret number was",  numberprint "Press any key to exit ..."m.getch()

This is a function of your shell, not Python. If you execute it in a shell, rather than double clicking on it in Windows (im assumgin youre doing that) it will work in the way you intended. See below.

root@paris3:~# python gistfile1.txtEnter an integer from 1 to 1,000: 192this is your 1 guessguess is lowEnter an integer from 1 to 1,000: 192this is your 2 guessguess is lowEnter an integer from 1 to 1,000: 192this is your 3 guessguess is lowEnter an integer from 1 to 1,000: 192this is your 4 guessguess is lowEnter an integer from 1 to 1,000: 999this is your 5 guessguess is highEnter an integer from 1 to 1,000: 777this is your 6 guessguess is highEnter an integer from 1 to 1,000: 444this is your 7 guessguess is lowEnter an integer from 1 to 1,000: 555this is your 8 guessguess is lowEnter an integer from 1 to 1,000: 666this is your 9 guessguess is highEnter an integer from 1 to 1,000: 580this is your 10 guessguess is lowThe secret number was 589root@paris3:~# 

To do what you are trying to do you can prompt the user for an input at the end of your program. you can see the last two lines in the ammended code I included at the top of this post.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×