woooee 814 Nearly a Posting Maven

Check itertools' product.

import itertools

list_1 = [1, 2, 3]
list_2 = [4, 5, 6]
x = itertools.product(list_1, list_2)
for y in x:
   print y

"""   My result
(1, 4)
(1, 5)
(1, 6)
(2, 4)
(2, 5)
(2, 6)
(3, 4)
(3, 5)
(3, 6)
"""
woooee 814 Nearly a Posting Maven

Use some kind of a switch that you turn on after the first instance is found.

import fileinput
string_found = False
for line in fileinput.FileInput("text.txt", inplace=1):
    if (not string_found) and ("hello" in line):
        line=line.replace("hello","hello2")
        print line
        string_found = True
woooee 814 Nearly a Posting Maven

This is where you run hit() for every square.

for i in range(self.y):
    for j in range(self.x):
        self.square[i][j]['command'] = self.hit(i, j)

Print i and j if you want to check it. Also, self.hit(i, j) does not return anything so self.square[j] will always be 'None'.

woooee 814 Nearly a Posting Maven

The second while/break statements in displayMenu() does nothing. You can delete them. And just use another function to write to the file.

def displayMenu(self):
        while True:
            print self.menu
            input = raw_input("");
            if input.upper() == "V":
##                while input.upper() == "V":
                    fileHandle = open ( 'scores.txt', 'r' )
                    str1 = fileHandle.read()
                    fileHandle.close()
                    print str1
  ##                  break

    def to_file(self):
        print "\nWould you like to save your score? (Y)es or (N)o:"
        save_it = raw_input()
        if save_it.upper() in ["Y", "Yes"]:
           fp = open(fname, "w")
           fp.write(all_the_stuff)
           fp.close()
woooee 814 Nearly a Posting Maven

You might want to re-think/modify the following.

if match:
    assign(filename, counter, path, extension)
    counter += 1
woooee 814 Nearly a Posting Maven

You have to strip() each line to get rid of spaces and newlines, and then test for length greater than zero. That will skip any lines with spaces only.

woooee 814 Nearly a Posting Maven

File "C:\Python26\getcard.py", line 22, in giveCard

It appears the error is in getcard.py, which you did not post, and not in testmod.py which you did post. The code you posted worked fine for me. BTW the following will only work for self.Tcard == 11, not if it equals 12 or 13.

if(self.Tcard <= 11 & self.Tcard != 14): 
              =================
                if(self.Tcard == 11):
                    self.Tcard = "J"
                if(self.Tcard == 12):
                    self.Tcard == "Q"
                if(self.Tcard == 13):
                    self.Tcard == "K"
                self.Sum+=10 
#
##----- a dictionary would work better than multiple if statements
card_dict = [ 11:"J", 12: "Q", 13:"K"}
if self.Tcard in card_dict:
    self.Tcard = card_dict[self.Tcard]

Finally, take a look at the Python Style Guide when you have time. It is easier to debug other people's code when we all use the same conventions http://www.python.org/dev/peps/pep-0008/

woooee 814 Nearly a Posting Maven

You can not mix canvas and grid. To use a label, button, etc. you must add a frame to the canvas. The following example will get you started on this, as well as using a for loop to create the square.

##-------  Do not import Tkinter twice; use one or the other
from Tkinter import *
##import Tkinter as tk
 
def startMenu():
    top_tk = Tk()
    top_tk.title("Checkers")
    top = Canvas(width="800", height="800")

    square_list = []
    color = "white"
    for j in range(0, 701, 100):
        square_list.append(top.create_rectangle(j,0,j+100,100, fill=color))
        if color == "white":
            color = "black"
        else:
            color = "white"

    fr = Frame(top, relief=GROOVE, borderwidth=2)
    label1 = Label(fr, text='Checkers', font=('Arial', 36), fg="blue")
    label1.pack(side="left")

    top.create_window(210, 800, window=fr, anchor=SE)
    top.pack(fill='both', expand='yes')
 
    top.mainloop()
 
startMenu()
smithy40000 commented: Thanks alot! helped greatly +0
woooee 814 Nearly a Posting Maven

I need to check if a float number has decimals or not.

Convert to a string, split on the ".", and see if the number after the decimal is greater than zero. You can also use divmod which returns the whole and decimal parts of a number
x = 2.5
print divmod(x, 1)
(2.0, 0.5)

woooee 814 Nearly a Posting Maven

You don't have a newline on the last line of the test data so "\n" is never found". You can add a newline to the data or test for EOF and if -1 is not a newline, then add one.

def test_func(thetext):
        for i in range(1,26):
            t = 0
            for x in range(0,len(thetext)):
                if thetext[x] == '\n' and thetext[x-1] == str(i) and thetext[x-2] == '\n':
                    print 'one'
                    t = 1
                    break
                if (thetext[x-1:x-2]) == str(i):
                    print 'two'
                    t = 1
                    break
            if t == 0:
                print "{TAB}{TAB} " + str(i)

test_list = [ "1\n",
              "5\n",
              "16\n" ]

for ltr in test_list:
   test_func(ltr) 
#
"""     My Results
one
{TAB}{TAB} 2
{TAB}{TAB} 3
{TAB}{TAB} 4
{TAB}{TAB} 5
{TAB}{TAB} 6
{TAB}{TAB} 7
{TAB}{TAB} 8
{TAB}{TAB} 9
{TAB}{TAB} 10
{TAB}{TAB} 11
{TAB}{TAB} 12
{TAB}{TAB} 13
{TAB}{TAB} 14
{TAB}{TAB} 15
{TAB}{TAB} 16
{TAB}{TAB} 17
{TAB}{TAB} 18
{TAB}{TAB} 19
{TAB}{TAB} 20
{TAB}{TAB} 21
{TAB}{TAB} 22
{TAB}{TAB} 23
{TAB}{TAB} 24
{TAB}{TAB} 25
{TAB}{TAB} 1
{TAB}{TAB} 2
{TAB}{TAB} 3
{TAB}{TAB} 4
one
{TAB}{TAB} 6
{TAB}{TAB} 7
{TAB}{TAB} 8
{TAB}{TAB} 9
{TAB}{TAB} 10
{TAB}{TAB} 11
{TAB}{TAB} 12
{TAB}{TAB} 13
{TAB}{TAB} 14
{TAB}{TAB} 15
{TAB}{TAB} 16
{TAB}{TAB} 17
{TAB}{TAB} 18
{TAB}{TAB} 19
{TAB}{TAB} 20
{TAB}{TAB} 21
{TAB}{TAB} 22
{TAB}{TAB} 23
{TAB}{TAB} 24
{TAB}{TAB} 25
{TAB}{TAB} 1
{TAB}{TAB} 2
{TAB}{TAB} 3
{TAB}{TAB} 4
{TAB}{TAB} 5
{TAB}{TAB} 6
{TAB}{TAB} 7
{TAB}{TAB} 8
{TAB}{TAB} 9
{TAB}{TAB} 10
{TAB}{TAB} 11
{TAB}{TAB} 12
{TAB}{TAB} 13
{TAB}{TAB} 14
{TAB}{TAB} 15
two
{TAB}{TAB} 17
{TAB}{TAB} 18
{TAB}{TAB} 19
{TAB}{TAB} 20
{TAB}{TAB} 21
{TAB}{TAB} 22
{TAB}{TAB} 23 …
woooee 814 Nearly a Posting Maven

Do it in one pass by converting to a dictionary of lists which can then be copied to the file.

test_list = [
    {'item1':3, 'item2':3, 'item3':5},
    {'item1':2, 'item2':6, 'item3':3},
    {'item1':18, 'item2':12, 'item3':1} ]

redone_dict = {}
for dic in test_list:
    for key in dic:
        if key not in redone_dict:
            redone_dict[key] = []
        redone_dict[key].append(dic[key])
print redone_dict
woooee 814 Nearly a Posting Maven

There any many ways to go about it. This uses a list of tuples.

"""
Thanksgiving: 11/ 26 - 11/28 
Winter Recess: 12/24 - 01/16
Martin Luther King's Birthday: 01/18
Presidents' Day: 02/15
Spring Recess: 03/15 - 03/20
Memorial Day: 05/31
Independence Day: 07/05/08
Summer Recess: 08/7 - 9/6
"""
def find_holiday(mm, dd):
                     # month, from_day, to-day, holiday name
    list_of_holidays = [ (11, 26, 28, "Thanksgiving"),
                         (12, 24, 31, "Winter Recess"),
                         (1, 1,   16, "Winter Recess"),
                         (1, 18, 18,  "MLK B'day"),
                         (2, 15, 15,  "Presidents' Day") ]

    for month, from_day, to_day, name in list_of_holidays:
        if (month == mm) and \
           (from_day <= dd <= to_day):
            print("%02d/%02d is %s" % (mm, dd, name)) 
            return

    print("%02d/%02d is not a school holiday" % (mm, dd)) 
    

mm = 12
dd = 25
find_holiday(mm, dd)
mm = 12
dd = 23
find_holiday(mm, dd)
woooee 814 Nearly a Posting Maven

It depends on whether you want to find sub-words or not. The simple example below shows the difference.

words_master = [ "the", "there", "theres"]

##--- look for word in list
word = "there"
if word in words_master:
    print(word, "found")
else:
    print(word, "Not found")

##--- compare each word in the list to the original word
print("-"*30)
for m_word in words_master:
    if m_word in word:
        print("%s found in %s" % (m_word, word))
woooee 814 Nearly a Posting Maven

This line does nothing

if len(modified) == 0 : continue

Look at the second word of the *new* list. If it does not contain
"trunk" or "branches", skip the line. (stuck on this)

Use the "in" keyword.

**---  will return a positive for words like "strunk"
found = False
for word in ["trunk", "branches"] :
    if word in words[1]:
        found = True
if not found:
    print "processing this"
doctorjo5 commented: this is helpful +0
woooee 814 Nearly a Posting Maven

For testing, cut the list down to 10 or 20 hex's and enter a value within that range. You are testing, so you want results in a reasonable amount of time. Also, note that some values are still missing. The following code will print the missing values. It can also be modified to generate the list instead of keying it manually.

charset = [
'01', '02', '03', '04', '05', '06', '07', '08', '09', '0b', '0c', 
'0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', 
'19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', 
'24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', 
'30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3b', 
'3c', '3d', '3e', '41', '42', '43', '44', '45', '46', '47', '48', 
'49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', 
'54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', 
'5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', 
'6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', 
'75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f']

k_range = [ str(x) for x in range(0, 10) ]
k_range.extend(['a', 'b', 'c', 'd', 'e', 'f'])
print k_range
for j in range(0, 8):
    for k in k_range:
        x = str(j) + k
        if x not in charset:
            print x
woooee 814 Nearly a Posting Maven

If you want to be sure that you only sample the same three values once, then you will have to keep track of the threesome somewhere, as each individual value could be used in another threesome. I don't know how many possible 4 digit permutations, randomly associated in triples there are, but it is a lot and probably would require more computing power than you have. You might want to consider testing for one group of the three at a time. That is, break the value you are testing against into it's component parts and find each one individually. Even better would be testing for the one-twelfth, each hex, individually. That should reduce the time from months to minutes. Finally, note the the "while True" loop never ends.

woooee 814 Nearly a Posting Maven

There is SpecTcl and VisualPython (3D) as well, but is anyone going to use a 'visual' front end to Tkinter. It is easier to generate your own code IMHO.

woooee 814 Nearly a Posting Maven

I would not support any spammer.

woooee 814 Nearly a Posting Maven

So, we are trying to make this more difficult than it is.

##--- populate a test dictionary
letters = 'HKWZA RRPVQ BIVYS MPDMQ MBUDC'
letters_dict = {}
for ltr in letters:
    if 'A' <= ltr <= 'Z':
        if ltr not in letters_dict:
            letters_dict[ltr] = 0
        letters_dict[ltr] += 1 

print(letters_dict)

## phi = f1 (f1 - 1) + f2 (f2 - 1) + ... + fn (fn - 1)
phi = 0
for ltr in letters_dict:
    qty = letters_dict[ltr]
    phi += qty * (qty-1)
print("Phi =", phi)

keys = letters_dict.keys()
keys.sort()
for ltr in keys:
    print("%s %7.2f" % (ltr, float(letters_dict[ltr])/phi*100))
woooee 814 Nearly a Posting Maven

Python uses references to point to a list, so you can use lists to do what you want. A linked list is one method used to do this depending on the specifics.

AllAtoms = {}
AllAtoms[0] = [0,[]]
AllAtoms[1] = [0,[AllAtoms[0]]]
AllAtoms[2] = [0,[AllAtoms[0]]]

print "Original"
for item in AllAtoms:
    print item, AllAtoms[item]

print "-"*50
AllAtoms[0].append(9)
for item in AllAtoms:
    print item, AllAtoms[item]

##-----  OR  -------------------------------------------------
print "-"*50
AllAtoms = {}
AllAtoms[0] = [[0],[1]]
AllAtoms[0][0] = [9]
AllAtoms[1] = [0,[AllAtoms[0]]]
AllAtoms[2] = [0,[AllAtoms[1]]]
for item in AllAtoms:
    print item, AllAtoms[item] 
#
#-----  My Output
0 [0, []]
1 [0, [[0, []]]]
2 [0, [[0, []]]]
--------------------------------------------------
0 [0, [], 9]
1 [0, [[0, [], 9]]]
2 [0, [[0, [], 9]]]
--------------------------------------------------
0 [[9], [1]]
1 [0, [[[9], [1]]]]
2 [0, [[0, [[[9], [1]]]]]]
woooee 814 Nearly a Posting Maven

I was thinking of something similar as Phi is generally associated with distributions, AFAIK, but note that the equation is
phi = f1 (f1 - 1) + f2 (f2 - 1) + ... + fn (fn - 1)
which looks like some sort of convoluted Fibonacci sequence. Can't do much more without further info.

woooee 814 Nearly a Posting Maven

I have to be misunderstanding the concept.

import random
import string

##--- populate a test dictionary with random quanties
letters_dict = {}
for ltr in string.uppercase:
    letters_dict[ltr] = random.randint(1, 100)

## phi = f1 (f1 - 1) + f2 (f2 - 1) + ... + fn (fn - 1)
phi = 0
for ltr in letters_dict:
    qty = letters_dict[ltr]
    phi += qty * (qty-1)
print phi
woooee 814 Nearly a Posting Maven

phi = f1 (f1 - 1) + f2 (f2 - 1) + ... + fn (fn - 1)

Someone is going to have to explain where f1, f2,... come from or what they mean.

woooee 814 Nearly a Posting Maven

The only things you can search for that I can see would be two colons in the line, str.count(), and if found, "Jan" through "Dec" (or "Mon" through "Sun" but they don't all contain the day). If they are both found, you can split and search for the string that has the colon in it, which should be the time.

woooee 814 Nearly a Posting Maven

I have always found it necessary to use shell=True, on Linux machines anyway.
p = call('DAZZLE tmp\163282.xml', shell=True)

woooee 814 Nearly a Posting Maven

In one of the "add up the cards" spots, print the cards as well. There is a problem with the way you access the class.

for i in self.hand:
                psum=int(i.value) + psum 
                print i.value, i.suit, i.rank

Or, add this print at the end of the class and then take a look at the deck loops. Print statements should be one of the first tools to use to determine what exactly the program is doing. Generally speaking, someone who has not tried this most basic of steps does not get much of a response.

self.cardname = self.rank + " of " + self.suit
        print self.cardname
woooee 814 Nearly a Posting Maven

Once you read a file, that is it, unless you go back to the beginning and start over again, so after the first pass, g.readlines() does nothing. Instead, I think it is save to store the whopping 15 lines in memory as a list and iterate over the list. In the future, you want to develop the habit of adding print statements to debug, which would show that nothing was happening after the first pass through the 'f' for() loop.

for line in f.readlines():
            for ln in g.readlines():
#
#---------- replace with
        g_data=open(self.dcmdir+"/DOPEN/extlib.ded",'r').readlines()
        f_data=open(self.dcmdir+"/DOPEN/dwnext.ded",'r').readlines()
        for line in f.data:
            for ln in g_data():
woooee 814 Nearly a Posting Maven

A string is always larger than a number (any number). Better re-read your other thread and if you are not sure, print type() for both variables.

woooee 814 Nearly a Posting Maven

For starters, you can use a dictionary and a list in the Card class. Test each class and function individually, whether it is in a class or not, before you include it your main program so you know that it works properly and returns the correct value. You obviously have too large of a program here for you to be able to debug.

class Card:
    def __init__(self, suit, rank):
        self.card_dict = {}
        self.card_dict[1]  = ["Ace", 11]
        self.card_dict[11] = ["Jack", 10]
        self.card_dict[12] = ["Queen", 10]
        self.card_dict[13] = ["King", 10]
       
        self.suit_list = ["*", "Clubs", "Spades",
                              "Diamonds", "Hearts" ]

    def rank_suit(self, suit, rank):
        if rank in self.card_dict:
            self.value = self.card_dict[rank][1]
            self.cardname = "%s of %s" % \
                 (self.card_dict[rank][0], self.suit_list[suit])              
        else: 
            self.value = self.rank
            self.cardname = "%s of %s" % \
                 (str(rank), self.suit_list[suit])
woooee 814 Nearly a Posting Maven

Try
line = line.strip() ## instead of line = line[:-1]
or make sure there is a return/newline in the last line of the file.

woooee 814 Nearly a Posting Maven

First, don't use "file" as a variable name as it is a reserved word. I would guess that the problem may be with counter equal or not equal to one, or not stripping spaces from the name or term. There were some punctuation errors in the code you posted as well. The following code, using test data, seemed to work for me with the above errors corrected. Finally, "fileappender" is unnecessary and slow in that you have to open and close the file each time. Just return the file pointer from the open() and use it to write.

def filereader (filename):
    """  commented -- using test data
    
    fp = open(filename ,'r')
    text = fp.readlines()
    fp.close()
    """

    text = ["fname1, term1", "fname2, term2", "fname3, term3" ]
    return text
 
def filewriter (filename, text):
    fp = open(filename ,'w')
    return fp
#    file.writelines(text)    
#    file.close()
 
 
resultsfile = 'C:\\resultsfile.txt'
fp_out = filewriter(resultsfile)
fp_out.write("Results File \n")

notes = filereader('C:\\mainlist.txt')

readfile_test = [ ["term1", "term4", "term1"],
                  ["term1", "term2", "term1"],
                  ["term1", "term4", "term3"] ]
ctr = 0
 
for item in notes:
    print "Line: " + item
    substrs = item.split(",")
    fname = substrs[0].strip()
    print "File: " + fname
    term = substrs[1].strip()
    print "Term: " + term
 
    fp_out.write("File : %s\n" % (fname))
    fp_out.write("Error: %s\n" % (term))
 
    ##--- use test data
    readfile = readfile_test[ctr]
    ctr += 1
#    readfile = filereader(fname)
    #print readfile
 
    counter = 0
 
    for subline in readfile:
        print "subline:" + subline
        if counter == 1:
            fp_out.write( "          %s\n" % (subline))
            print "     c0sub: " + subline
            counter …
woooee 814 Nearly a Posting Maven

I have this example from somewhere on the web that changes based on the slider value. You are interested in the moveSlider and valueChanged functions. Sorry, I didn't note where i came from.

Edit: Just noticed that you are using Qt3, so try this program instead. I don't have Qt3 installed so can't test it.

"""**************************************************************************
** $Id: rangecontrols.py,v 1.1 2003/07/01 14:18:37 phil Exp $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
***************************************************************************"""

import sys
from qt import *

INT_MAX = sys.maxint

class RangeControls( QVBox ):
    def __init__( self, parent=None, name=None ):
        QVBox.__init__( self, parent, name )
        
        row1  = QHBox( self )
        cell2 = QVBox( row1 )
        cell2.setMargin( 10 )
        cell2.setFrameStyle( QFrame.WinPanel | QFrame.Sunken )

        QWidget( cell2 )

        label1 = QLabel( QString( "Enter a value between\n%1 and %2:" ).arg( -INT_MAX ).arg( INT_MAX ), cell2 )
        label1.setMaximumHeight( label1.sizeHint().height() )
        sb1 = QSpinBox( -INT_MAX, INT_MAX, 1, cell2 )
        sb1.setValue( 0 )

        label2 = QLabel( "Enter a zoom value:", cell2 )
        label2.setMaximumHeight( label2.sizeHint().height() )
        sb2 = QSpinBox( 0, 1000, 10, cell2 )
        sb2.setSuffix( " %" )
        sb2.setSpecialValueText( "Automatic" )

        label3 = QLabel( "Enter a price:", cell2 )
        label3.setMaximumHeight( label3.sizeHint().height() )
        sb3 = QSpinBox( 0, INT_MAX, 1, cell2 )
        sb3.setPrefix( "$" )
        sb3.setValue( 355 )

        QWidget( cell2 )

        row2 = QHBox( self )

        cell3 = QVBox( row2 )
        cell3.setMargin( 10 )
        cell3.setFrameStyle( QFrame.WinPanel | …
woooee 814 Nearly a Posting Maven

Works fine for me (using the following stripped down version). You should include the actual error when posting; it is not always what you think it means.

class Card():
        SUIT = { 'C':'Clubs', 'D':'Diamonds', 'H':'Hearts', 'S':'Spades' }
        VALUES = { '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, \
                        '10':10, 'J':12, 'Q':13, 'K':14, 'A':15 }
 
        def __init__(self):
            print("Card class instance")


class PokerHand():
        SIZE = 5
        RANKS = { 0: "Straight Flush", 1: "Four of a Kind", 2: "Full House", \
                        3: "Flush", 4: "Straight", 5: "Three of a Kind", \
                        6: "Two Pairs", 5: "Pair", 6: "High Card" }
 
        def __init__(self):
            print("PokerHand class instance")
            print("From PokerHand")
            self.issflush()

        def issflush(self):
            print(Card.VALUES)

PH = PokerHand()
print("\nFrom main")
print(Card.VALUES) 
print("\nissflush")
print PH.issflush()
woooee 814 Nearly a Posting Maven

I understand there is a language barrier so please explain if and how you identify this record

For example program read <HEADLINE text="This is headline 1"> and write to the sec. file:

if you are not using startswith(), and we can go on from there. If you have existing code that does this, or anything else, please post the code, or at least a summary of it, so we don't cover things already completed.

woooee 814 Nearly a Posting Maven
woooee 814 Nearly a Posting Maven

Use startswith() on each record to test for <HEADLINE and the string find function to locate the double quotation marks.

woooee 814 Nearly a Posting Maven

See if adding this print statement gives you any ideas.

# New board function
def new_board():
    """Create new game board."""
    board = []
    for square in range(NUM_SQUARES):
        print "adding square #", square
        board.append(EMPTY)
        return board
Cjreynol commented: Very very helpful, helped me work out a bug I had been having lots of trouble with! +0
vegaseat commented: nice help +10
woooee 814 Nearly a Posting Maven

print "\n\t", board[0], "|", board[1], "|", board[2]
IndexError: list index out of range

Add a
print len(board)
as the first statement in the function to see if your list contains 9 items (and of course it doesn't, but this will tell you how many items it does contain).

woooee 814 Nearly a Posting Maven
(r**2) = (x**2) + (y**2) ## syntax error here reads "***cannot assign operator"

This is obvious. You can not solve for r squared. You would have to use

r2 = (x**2) + (y**2) ## syntax error here reads "***cannot assign operator"
r = r2 **0.5
or r = math.sqrt(r2)
woooee 814 Nearly a Posting Maven

Use the modulo "%" which gives the remainder.

for x in [1.1, 1.8, 1.0]:
   if x % 1 > 0:
      y = int(x)+1
      print y
   else:
      print "no conversion for", x 
#
# prints
2
2
no conversion for 1.0
woooee 814 Nearly a Posting Maven

print score(0,-9)
will trigger the last return in this block of code, because x=0. Note that the "y" portion of the code will never be reached, because any value of x will result in a return from the function.

if x>15 or x<-15:
        print "Out of Bounds, No Points"
        return 0
 
    else:
        if x>12 or x<-12:
            return 20
 
        else:
            if x>9 or x<-9:
                return 40
 
            else:
                if x >6 or x<-6:
                    return 60
 
                else:
                    if x >3 or x<-3:
                        return 80
 
                    else:
                        ##======================================
                        ##  x=0 will wind up here
                        ##======================================
                        return 100

Also, you could do something a little more succinct like the following.

if x>15 or x<-15:
        print "Out of Bounds, No Points"
        return 0
## else is not necessary since you have a return that will exit the function if > 15 
test_list = [ (12, 20), (9, 40), (6, 60), (3, 80)] 
for num, ret_val in test_list:
    if abs(x) > num:
        return ret_val

##  nothing found earlier = abs(x) <= 3
return 100
woooee 814 Nearly a Posting Maven

spell = []
defines an empty list on every pass through the loop. You want it before the while(). Also, your code is an infinite loop, i.e. there is no exit.

woooee 814 Nearly a Posting Maven
woooee 814 Nearly a Posting Maven

I am not a user (of regex's) so would do something like the following. You might prefer to find the first "&" and slice from there instead of using split and join.

test_data = ["sometext herekeywords=walter&keywords=scott",
             "keywords=john&sometexthere",
             "keywords=james&keywords=john& keywords=brian&"]

delim = 'keywords='
found_list = []
for rec in test_data:
   ## find all occurances of 'keywords='
   start = rec.find(delim)
   ctr = 0     ## I always limit while loops when testing
   while (start > -1) and (ctr < 10):
      rec = rec[start+len(delim):]  ## everything after delim
      if "&" in rec:
         substrs = rec.split("&")
         found_list.append(substrs[0])  ## before first "&"
         rec = "&".join(substrs[1:])  ## put the rest back together
      else:
         found_list.append(rec)

      start = rec.find(delim)
      ctr += 1

print found_list
#
# output is ['walter', 'scott', 'john', 'james', 'john', 'brian']
woooee 814 Nearly a Posting Maven

There are many ways to flatten a list. Here are two. I'm sure a Google would come up with many more.

a = [[1,2,3], [4,5,6], [7,8,9]]
b = [num for sublist in a for num in sublist]
print b

import itertools
c = itertools.chain(*a)
print list(c)
woooee 814 Nearly a Posting Maven

And you can use a dictionary as a container for all of this, so if you want to change anything, you just add, change, or delete from the dictionary. Your code assumes that just one hit will be found. If there is more than one, "person" will be whatever was found last.

test_dict = {}
test_dict['Arts'] = 'person1'
test_dict['Book'] = 'person2'
test_dict['Learning'] = 'person3'
if system == 'Conferences':
    person = ""
    for key in test_dict:
        if key in communities:
            person = test_dict[key]
    if len(person):     ## something was found
        assignedtomatrix[system]['Third'] = person
woooee 814 Nearly a Posting Maven

See if adding this print statement clears things up. You have to compare the same type of variables, i.e. an integer to an integer, etc.

def Marks(*score):
    print score, type(score)
    marks0 = 0
    marks1 = 0
    marks2 = 0
    marks3 = 0
    marks4 = 0
    marks5 = 0

    if score == 0:
        marks0 = marks0+1
    elif score == 1:
        marks1 = marks1+1
    elif score == 2:
        marks2 = marks2+1
    elif score == 3:
        marks3 = marks3+1
    elif score == 4:
        marks4 = marks4+1
    elif score == 5:
        marks5 = marks5+1

    print "0 marks scored by", marks0 , "people."
    print "1 mark scored by", marks1 , "people."
    print "2 marks scored by", marks2 , "people."
    print "3 marks scored by", marks3 , "people."
    print "4 marks scored by", marks4 , "people."
    print "5 marks scored by", marks5 , "people."

Marks(1)

Also you can use a list instead of 6 variables.

def Marks(*score_input):
    marks_list = [0, 0, 0, 0, 0, 0]
    for score in score_input:
        if score < 6:
            marks_list[score] += 1
        else:
            print "Bogus score entered ----->", score

    for score in range(6):
        print "%s marks scored by %d people." % \
                 (score, marks_list[score])

Marks(1, 3, 3, 7, 5)
vegaseat commented: very helpful +10
woooee 814 Nearly a Posting Maven

The return statement is still in the wrong place. You return from the function after the first flip. See Vegaseat's or my previous post.

woooee 814 Nearly a Posting Maven

This function returns on the first pass through the loop.

def simulateFlips(times):
    import random
    heads = 0
    tails = 0
    for i in range(times):
        if random.randint(1,2) == 1:
            heads += 1
        else:
            tails += 1
        return (heads, tails)

## it should be
    return heads,  tails

Also you have to convert to a float when dividing
print (float(heads)/times*100), "Heads Probability."
and pass "times" to the function displayResults.

woooee 814 Nearly a Posting Maven

the problem is that import queue and import Queue dont work

In your original example, Queue imported fine. It was the statement calling Queue that was the problem. Try the first two lines of redyugi's example and see what you get.

from Queue import Queue   ##<----- imports fine
def main():
 
   ##=========================================================
   ## line 19 (here) is the problem
    q = Queue.Queue()....

Traceback (most recent call last):
File "D:\Python26\test.py", line 166, in <module>
main()
##=========================================================
## line 19 (here) is the problem
File "D:\Python26\test.py", line 19, in main
q = Queue.Queue()
AttributeError: class Queue has no attribute 'Queue'