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.
Thanks

Recommended Answers

All 7 Replies

I'm a beginner myself so...

if numInput > 3:
   print "Statement here..."
else:
   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
    else:
         print "Try Again"
if numInput > 3:
    print "The Number is below 3."
else:
    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.?

numInput is nowhere in program!

numInput is nowhere in program!

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

I do not know what is your purpose for that as it does not exist.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.