1,105,295 Community Members

No Errors but no output either.

Member Avatar
LinaClark
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have finished the code, but I can not for the life of me figure out why I am not getting any output. Any help would most appreciated.

#!/usr/bin/python

import apsw
import random

class NonRepeatingRandom(object):

    def __init__(self, maxvalue):
        self.maxvalue = maxvalue
        self.used = set()

    def next(self):
        if len(self.used) >= self.maxvalue:
            raise StopIteration
        r = random.randrange(0, self.maxvalue - len(self.used))
        result = 0
        for i in range(1, r+1):
            result += 1
            while result in self.used:
                 result += 1
        self.used.add(result)
        return result

    def __iter__(self):
        return self

    def __getitem__(self):
        raise NotImplemented

    def get_all(self):
        return [i for i in self]

class Game:

    def __init__(self):
        global connection
        global cursor
        connection=apsw.Connection("atlstops.db3")
        cursor=connection.cursor()

    def User(self):
        user = raw_input("What is your name? ")
        user_number = NonRepeatingRandom(100)
        person = {}
        person['user'] = user
        person['number'] = user_number


    def Level1(self):
        sql = "SELECT easyhint, gps FROM venues WHERE quad = 1 ORDER BY RANDOM () LIMIT 1;"
        result = [] 

        try:
            cursor.execute(sql)
            result = cursor.next()
        except Exception, e:
            print e

        for row in result:
            while 'easyhint' < 8:
                if 'gps' in row and 'number' in self.person:
                    return row.easyhint.itervalues()
                else:
                    return 0


    def Level2(self):
        sql = "SELECT mediumhint, gps FROM venues WHERE quad = 1 or 2 or 3 ORDER BY RANDOM () LIMIT 1;"
        result = []

        try:
            cursor.execute(sql)
            result = cursor.next(size = 7)
        except Exception, e:
            print e

        for row in result:
            while 'mediumhint' < 8:
                if 'gps' in row and 'number' in self.person:
                    return row.mediumhint.itervalues()
                else:
                    return 0

    def Level3(self):
        sql = "SELECT hardhint, gps FROM venues ORDER BY RANDOM () LIMIT 1;"
        result = []

        try:
            cursor.execute(sql)
            result = cursor.fetchmany(size = 7)
        except Exception, e:
            print e

        for row in result:
            while 'hardhint' < 8:
                if 'gps' in row and 'number' in self.person:
                    return row.hardhint.itervalues()
                else:
                    return 0

class StartOptions: 

    glevel = raw_input("Choose you level:")

    def Easy(self):
        gme = Game()
        easy = True
        if easy:
            return gme.Level1()

    def Medium(self):
        gme = Game()
        self.easy = False
        medium = True
        if medium:
            return gme.Level2()

    def Hard(self):
        gme = Game()
        self.easy = False
        self.medium = False
        hard = True
        if hard:
            return gme.Level3()

def screen_output():
    start = StartOptions()
    print start.glevel
    if start.glevel == "easy":
        print "Your hint is:", start.Easy()
    elif start.glevel == "medium":
        print "Your hint is:", start.Medium()
    elif start.glevel == "hard":
        print "Your hint is:", start.Hard()
    else:
        print "Try again..."

Like I stated in the title, no errors show when I run it. I would also take suggestions on how to make it better too.

Member Avatar
Lucaci Andrew
Master Poster
746 posts since Jan 2012
Reputation Points: 128 [?]
Q&As Helped to Solve: 116 [?]
Skill Endorsements: 18 [?]
 
0
 

But do you call the fuction accordingly?

screen_output()
Member Avatar
LinaClark
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Yes. I left that part out of the code by mistake.

Member Avatar
Gribouillis
Posting Maven
3,453 posts since Jul 2008
Reputation Points: 1,140 [?]
Q&As Helped to Solve: 883 [?]
Skill Endorsements: 18 [?]
Moderator
 
1
 

There is something strange in this code

>>> 'easyhint' < 8
False

You are comparing constant strings to integers. You probably meant something else. This needs to be corrected.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article