I have a question about the raw_input
function.
I made a small number-guessing game as a small project, and if you don't want to play it states "goodbye". However, I have put it as a raw_input
so the program only closes after you press Enter.
The problem with this is that the program completely looks over the raw_input
bit, whereas using print("")
instead works.
Have I made a mistake anywhere? Here is the code:
import random
from random import randint
Number = 0
Guess = 0
while True:
Decision = raw_input("Do you want to play a round of number guess?(Yes/No)")
if Decision == "Yes":
Number = randint(0,100)
while True:
Guess = input("What number will you guess?")
if Guess == Number:
print("Correct!")
break
if Guess > Number:
print("Too big!")
if Guess < Number:
print("Too Small")
elif Decision == "No":
print("Oh well")
break
else:
print("I'm not what that means...")
raw_input = ("Goodbye")
Consider this line from your program:
raw_input = ("Goodbye")
This line does not invoke the raw_input()
function. Rather, it rebinds the global name raw_input
to the string "Goodbye"
. Since this is the last line of your program, this line has no practical effect.
If you want the program to pause before exiting, try this:
raw_input("Goodbye")