1

I'm making a candy box game, but i cant get the input to work. The other problem is it prints 'You have 1 sweet.' and then stops. Please help?

import time, sys
print("Sweetie box")
sweets = 0
while True:
    time.sleep(1)
    sweets += 1
    print("You have ", sweets, " sweets.")
    INPUT = input()
    if INPUT == ("a"):
            print("It worked!")
2
  • 1
    You need to call the function input(). Commented Nov 21, 2013 at 18:25
  • Sounds like you want the number of sweets to continuously update, even while waiting for the user to make a move. That's not very easy to do on the command line with just built-in functions. Perhaps you should consider a UI lib like Tkinter -- then you could update your labels every second while still watching buttons/text boxes for input from the user. Commented Nov 21, 2013 at 19:41

1 Answer 1

1

You need to invoke the input built-in by adding () after it:

INPUT = input()

Right now, you have INPUT being set to the built-in itself. See a demonstration below:

>>> x = input
>>> x
<built-in function input>
>>> x = input()
word
>>> x
'word'
>>>
Sign up to request clarification or add additional context in comments.

4 Comments

Yeah, thanks. I've just edited with a second problem
@user2916424 - If you are seeing what I think you are, then that is the input prompt. You have to enter something and then press ENTER. I tested your code and it works fine.
i get that you have to press enter, it's just the sweets should update without having to have an input. D'ya know what's wrong?
@user2916424 - Hmm. I ran this in Python 3.3 and sweets did update. Just, you had to enter something first. If you don't want an input, why not remove it altogether?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.