Try this:

if stguess == 'new':
           thisanswer = random.randint(1, 100)
           answer=Answer(ans = thisanswer)
           answer.put()


elif stguess != 'new':
           try:
               stguess = int(stguess)
               q = db.GqlQuery("SELECT * FROM Answer")
               q = q.fetch(1)
               answer = q*[0]*
if stguess < answer:
                   msg = ('Your guess ' + str(stguess) + ' is too
low' + str(answer*.**ans*))

You also need to deal with a possible index error when answer = q*[0]*

On Tue, Aug 16, 2011 at 9:09 PM, Matt <mpiechow...@gmail.com> wrote:

> I'm working on my first webapp, it's a simple guess the number game
> and I'm confused on using the data store. I use the datastore to store
> and retrieve the current answer.
>
> I have this which stores the current answer
> class Answer(db.Model):
>    ans = db.IntegerProperty()
>
> If the user enters 'new' then the new answer is created and stored in
> the database
> if stguess == 'new':
>            thisanswer = random.randint(1, 100)
>            answer=Answer(ans = thisanswer)
>            answer.put()
>
> If they don't want a new game then take the current answer to compare
> to users guess
> elif stguess != 'new':
>            try:
>                stguess = int(stguess)
>                q = db.GqlQuery("SELECT * FROM Answer")
>                q = q.fetch(1)
>                answer = q
>
> When I guess it always shows up as an answer of too low. I wrote this
> to check what answer was when I pulled from the datastore -
>
> if stguess < answer:
>                    msg = ('Your guess ' + str(stguess) + ' is too
> low' + str(answer))
>
> msg is displayed on screen and I get this -
>
> Your guess 33 is too low[<__main__.Answer object at
> 0x0000000003C0EF98>]
>
> Does anyone know what that part following low is? It looks like a
> memory address to me. And does anyone know why I cannot pull out the
> random number as an integer in my example... any idea of what I can
> change?
>
> Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to google-appengine@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to