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.

Recommended Answers

All 3 Replies

But do you call the fuction accordingly?

screen_output()

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

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.

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.