I have recently made a guessing game code and I am now trying to make it so when you enter a number above 3, it will give a print command that i will write. I don't need help on the print command, I just need to know what the string for any number above 3 is.

Edited by bob24bob: n/a

7 Years
Discussion Span
Last Post by pyTony

I'm a beginner myself so...

if numInput > 3:
   print "Statement here..."
   print "Default statement here..."

this is the code that I have for the guessing game itself.

import random
f = 0
num = random.randint(1, 2)
print "Guess a number either 1 or 2"
while f == 0:
    theGuess = int(raw_input("Enter number: "))
    if theGuess == num:
         print "Good Job"
         f = 1
         print "Try Again"
if numInput > 3:
    print "The Number is below 3."
    print "The Number is below 3."

This is what happens when I try to use the code:

Guess a number either 1 or 2
Enter number: 3
Try Again
Enter number: 2
Try Again
Enter number: 1
Good Job
Traceback (most recent call last):
  File "Z:\Guessing Game.PY", line 13, in <module>
    if numInput > 3:
NameError: name 'numInput' is not defined

As you can see, the code for printing something different when above 3 hadn't worked, as well as the numInput is not defined also.?

Edited by bob24bob: n/a


numInput is nowhere in program!

I am a beginner at this! how do i put in numInput?


okay, nevermind about that. if i was to make a command named numInput, how would I make it so that numInput was the number you entered?


I would name it number_input and use while and try..except..else constructs to define it.

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.