-1

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")
Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Python
  • 1
  • 3
  • 1
    you are comparing an `int` (`Number`) to a `str` (`Guess`). ...and on the last line you are overwriting `raw_input` with `'Goodbye'` (which is probably the first thing you must fix). – hiro protagonist Jan 09 '17 at 19:11
  • 3
    `raw_input = ("Goodbye")` replaces the `raw_input` function with the string `"Goodbye"`. I think you just want `raw_input("Goodbye")` – Patrick Haugh Jan 09 '17 at 19:14

1 Answers1

0

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")
Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • Shouldn't s(he) be using `input()`? It looks like Python 3. – Aryaman Jan 09 '17 at 19:20
  • 2
    It can't be Python3, author implies that it runs fine up to that point. If it does otherwise run, then the previous usage of `raw_input()` and `input()` indicate Python2. I don't know why author uses the functional notation `print()`. – Robᵩ Jan 09 '17 at 19:22