Murtan 317 Practically a Master Poster

Why would your implementation using zip be better than the OP's implementation?

Would zip better support any of the other transforms that are coming? (To search for words that are right-to-left or bottom-to-top in the original grid.)

Would zip even support a diagonal transform? (The documentation seems to indicate that it favors rectangular transforms.)

OP's transform using join:

[''.join([r[col] for r in grid1]) for col in range(len(grid1[0]))]
Murtan 317 Practically a Master Poster

I like your concept of transforming the original grid, so you can always search 'left-to-right' (its not how I thought about the problem).

Will you need to be able to search for diagonal words?

If so, can you make that transform as well?

For looking for a given word (on a given line of a given transform) you can use the find function.

'xxredxxx'.find('red')
# returns 2
'xxredxxx'.find('blue')
#returns -1
Murtan 317 Practically a Master Poster

Well there is the join function...

''.join(['a','b','c'])
# returns 'abc'

does that help?

Murtan 317 Practically a Master Poster

The read method should not call writefile() You should call it from your main. Where you have

x.read();

You should have

x.read();
x.writefile(ofile);

Note that I passed the file to write to, so stop opening and closing the file in writefile That may be the cause of your double recording, you had the file open twice.

Your main is not supposed to read the file data itself, it is supposed to use the readfile method and then call the show method to display the record. Then it should call getgpa to get the gpa for the average calculation.

(What you have probably works, but does not meet the requirements.)

Murtan 317 Practically a Master Poster

So your main shoud do something like the following:

Open the student.dat file (for output)
Read in a student from the keyboard
Write the student data to the file
(until you see the EOF at the keyboard)
Close the file

Open the file
Read in a student from the file
Show the student
get the gpa to use in calculating the average
(until you run out of data in the file)
close the file

print the average gpa

The above is an outline for your main. Start there, attempt to write your main using the above description, modifying it if you find the need. The above code will be implemented by calling the methods that you have been asked to write.

Once you have the main implemented you can flesh-out the methods if they're not doing what you need them to. It should also help you to better understand how the methods are intended to 'fit' into the program you need to write.

Murtan 317 Practically a Master Poster

I would agree that it does not look like it is quite linked up right.

Where is the Applicant class defined? (I see Applicant app but not the class, does this compile?)

I'm not sure, but it appears that you are repeating some (or all) of the data from the Applicant inside the Employeelink (which contains an Applicant). This is normally an indication of a faulty design.

The class Promosion appears to contain a (doubly) linked list of Employeelink instances.

The method Promosion::linkup(Employeelink applicant, Applicant app) appears to want to add a new Employeelink to the list. The method should always set both the next and before members of the Employeelink. The before is only set if the records we added was the first. And the next always points to where lastone was pointing, but then lastone is set to point to the new record.

I wish I could draw pictures in here...they seem to work the best to describe how this should work, but I'll try to do it in text.

Initially, the list is empty. (start = null, lastone = null)

When you add the first record (we'll call it A for now)

start -> A, lastone -> A, A.before -> null, A.next -> null

Now when you add B, you would normally add it at the head or the tail of the list (unless its an ordered list, but I don't see any support for that). This example …

Murtan 317 Practically a Master Poster

I will comment however that users tend to like things to start at 1 rather than 0.

If I'm asking a user questions, it makes more sense to them to answer questions 1 - 10 rather than questions 0 - 9.

This is however also easily handled at the output point:

for (int ii = 0; ii < 10; ii++)
{
    printf("Question #%d:\n", ii+1);
}

The loop still ran from 0 to 9, making it more compatible with arrays, but the user 'sees' 1 to 10.

Murtan 317 Practically a Master Poster

The if is the proper construct. You couldn't replace them with while or do/while without significant restructuring of the methods.

I will note however that the remove method could be improved. It presently will 'leak' the newitem that it created. (The creation of which was entirely un-necessary.) The method will also fault in ListItem * next = head->getNext(); // Initialize next pointer if the list is empty (head == null).

Murtan 317 Practically a Master Poster

If I ever wrote methods like writefile(...) and readfile(...) for a class that was to be streamed to/from files, I would pass the file handle (or stream) as an argument to the method so that it didn't have to worry about opening the file or closing the file. It would also allow me to call it multiple times for the same file which could write (or read) multiple records from the same file.

The only other logical implementation for a readfile member would be for a 'class owned' rather than 'instance owned' method. The method would read and instantiate multiple student records from the file. It should however either return the list of student records or be updating a global list. (The return of the list tends to be more flexible in the future.)

Is there more that you were given? (function prototypes for example) or is the first paragraph (before your code) all that you were given for the assignement?

Murtan 317 Practically a Master Poster

Please use code tags to wrap your code.

Your code as posted:

house = ["TV", "computer", "phone", "playstation", "Wii", "EMPTY"]
print "items in my house are: "
print house

house = ["TV", "computer", "phone", "playstation", "Wii", "EMPTY"]
print "Pick an item to fill in the empty space: \n1 =TV\n2 = computer\n3 = Wii\n\n"
item =raw_input("\nYou chose: ")

house[6] = item
print "Items in my house are now:"
print house

In line 5, you re-assign the value of house, there is no point.

From the linked picture, the options in line 6 should be things that are NOT already on the list.

In line 7, item will contain whatever the user entered. The linked picture indicates that you should be performing input validataion.

The assignment in line 9 will assign whatever the user typed, if they followed the directions it will be "1", "2" or "3". You need to do a lookup of some kind and add the appropriate item based on the number that the user entered.

Other than that, you're not too far off.

Murtan 317 Practically a Master Poster

The current implementation only looks at the first record returned and builds an output string with the question and answer options.

If there was more than one question matched, how would it work?

Should this return all of the questions delimited in some fashion?

Should it always return a list of questions, that might be empty?

Should you pass a question index into this method and keep calling it until it returns something indicating no more questions?

How would the user interact with it?
Would all of the questions for the day be on the same page, or would you want one page per question?

Murtan 317 Practically a Master Poster

Close, but the line 4 needs to follow like 5 and print the len of the random_word.

As written, line 4 (if it used 'len' instead of 'leg') would tell you how many words there were.

print "I'm picking one of my", len(word_list), "words."
random_word = random.choice(word_list)
print "My secret word has", len(random_word), "letters."
Murtan 317 Practically a Master Poster

The problem wasn't to remove references to random_word but to set it to a random selection from your list of words.

You use guess_word in many places to mean many different things, this is generally 'bad form'.

Initially, it is the array of words:

guess_word = ['python', 'jumble', 'easy', 'difficult', 'answer', 'tracer', 'muffin']

Then later you assign it from the word that the player entered

word=raw_input("What say you (hit Enter to quit) ")
guess_word = word

So, to help me out:

Use word_list to refer to the list of words to pick from.

Set random_word to be one of the words from the word_list. (Try using random.choice)

Oh, and in a previous version, you told them how many letters were in the random word, if it is permissable still, do something like

print "My secret word has", len(random_word), "letters"

For testing / debugging, I usually add something so I can see the word. (Remove it before you turn it in or give it to someone else to play.)

print "** DEBUG: Word:", random_word, "**"

When you're validating letter guesses, see if they are in the random_word.

After the 5 guesses, have the user enter the guess_word you should strip() and lower() the guess.

Then compare the guess_word to the random_word to see if they guessed correctly.

Murtan 317 Practically a Master Poster

The while loop starting on line 45 is NOT supposed to be inside the while loop from line 10. Move it out to the same level as the while from line 10.

You can not run the posted code...the posted code doesn't select or define random_word before the test on line 22. When I run it, it stops there.

When I've fixed both of the above, I'm not seeing the error you describe. What did you enter for the guess?

Murtan 317 Practically a Master Poster

Will the grid really contain 'x' where it doesn't have a word?

Is it defined that all words will start at the left and go right, or start at the top and go down?

If there are going to be other letters in the grid, it would help to have a list of the words you are expected to find.

As a place to start, how would you go about solving the problem manually. If YOU had to search the grid to find the words, describe how you would you go about it.

Can you think of how to make the computer do the same thing you would do?

Murtan 317 Practically a Master Poster

In your description of MyEvent, I didn't see where any data from the background worker was transferred to the form.

Could you describe a little more about that, maybe it will have a clue.

Murtan 317 Practically a Master Poster

Change the return on line 34 and on line 37 to break to allow the while loop started on line 29 to exit.

Murtan 317 Practically a Master Poster

First, just to confirm: You shouldn't see this problem at all on the system where you developed the applicaiton. The error should be occuring on a target system where you are attempting to run your application. Correct?

Second, the corrective actions (DLLs, MDAC) are being performed on the target system. Correct?

When the list below mentions <windows system> it is referring to the system directory underneath the target system's windows directory. When it mentions <program fiels> it is referring to where the target system stores installed programs. (This last one is almost always C:\Program Files, but the windows installation directory moves around more.)

So you are confirming that all of the files mentioned are installed on the target system?

<windows system>\Msdbrptr.dll
<program files>\Common Files\Designers\Msderun.dll
<windows system>\Msstdfmt.dll
<windows system>\Msdatrep.ocx
<windows system>\Msbind.dll

If the above is true and the application still does not work on the target system, copy the files targeted to <windows system> to <windows system32> (if the target system has one) as well:

<windows system32>\Msdbrptr.dll
<windows system32>\Msstdfmt.dll
<windows system32>\Msdatrep.ocx
<windows system32>\Msbind.dll

Does this help at all?

Murtan 317 Practically a Master Poster

I think jlm699's code was just an example of how you might extend tuples (because you said you couldn't use lists.) I don't think it was intended to be a specific example for your program.

Did you read my previous message about how I thought you ought to structure the main part of your program?

for guesscount in range(1,6):
        lguess = raw_input("Enter your letter guess #%d" % guesscount)
        # put an if test here along with the 'yes' or 'no' display
    # They've run out of letter guesses
    guess_word = raw_input("What do you think the word is? ")
    # test and output here

You don't have to follow my advice specifically, but the current structure you have will not work. The two consecutive while loops don't perform like the game should. Once you get a letter right, there is no way to get back to the loop for getting a letter wrong.

You need some form of outside loop, and the while loops really should be IF statements.

New topic:

Are you even trying to run your code? What errors are you seeing?

(I get an error after my first guess...what do you see?)

#hint you need to initialize tried_good and tried_bad as tuples
tried_good = ()
tried_bad = ()
# I know I told you to make them 0 before, but I thought you were
# counting guesses, not collecting them
#
#Then you need to do something like what jlm699 …
Murtan 317 Practically a Master Poster

If the program you are trying to intercept is a DOSBOX program (which I read to mean a program written before windows, but that will be run under windows) that does help clarify what you will need to do.

Because it is a DOSBOX program, it probably will just send the characters to the printer. There may be few control codes mixed in, but it should be fairly easy to filter them.

There were a couple of DOS TSR based programs that would intercept calls to the printer and direct them to a file (See for example PRN2FILE, source code if you can find it)

These programs no-longer work under the modern windows interaface as they worked using a DOS concept calls TSR (Terminate Stay Resident) which allowed them to remain in memory to handle the calls, but that is no-longer available with Windows.

Can you have your program 'launch' or 'start' the other program?

If so, you might be able to 'pre-setup' its runtime environment such that when it goes to print, your 'wrapper' program gets the data instead. I know that being the 'launcher' of an application can give you additional rights releated to the application when it runs.

I am unfortunately 'stuck' at this point as I can't find a resource to direct you to for more information, but don't have any more time to spend right now either.

Murtan 317 Practically a Master Poster

I was trying to understand what he wanted to accomplish so I restated the problem. It did appear to me that the output array was an index into the the original array, but I wanted the original poster to confirm my understanding.

(If there's another thread, I didn't see it either -- sigh)

Murtan 317 Practically a Master Poster

If the array entered was:

40
20
10
30

I think the output should be:

2
1
3
0

Does it look like I understood the what the program is supposed to do?

I will not just solve your problem. I will help YOU solve your problem.

If you're writing a program, it will need to do the following:
1) Accept the user input for the array
2) Generate the output array
3) Display the output array

Have you written anything yet?

If so, which parts have you addressed?

Murtan 317 Practically a Master Poster

So if I understand it correcly, your application has 4 windows. The main window and 3 other forms. The 3 forms are updated by backgroud worker threads.

Does the program always create all 3 forms, even if they are not visible?

Does the program always start the 3 background threads, or does it wait until the associated window is set to visible?

If the thread starts when the window is set to visible, are there any provisions to suspend or terminate the thread when the window is hidden?

Can you identify whether it is the close of the first window or the open of the second window that is causing your lockup?

How does the background thread interface with the window?

As I say the above, I seem to remember that you can (or could) generate problems when making calls into methods of the window (form) from more than one thread.

Murtan 317 Practically a Master Poster

That looks like a mass-mailing application...not sure I WANT to help, but does it just not work or are you getting an exception?

If you're getting an exception, what is it?

If it just "doesn't work", what debugging (to ensure you are getting the right parameters set) have you done?

Murtan 317 Practically a Master Poster

There are several possibilities for 'getting between'.

In the end, you will end up providing an interface to the program that must act as it expects the 'LPT' to act.

To better understand the problem:

Does the program think that a printer is attached to the LPT or is it some other device?

What Operating System does the program run under?

Does the program have any configuration to select the LPT or printer?

I doubt this is an option, but is it possible for you to modify and re-build the program?

The source code you included appears to be for Windows. Almost all Windows applications allow you to select the printer to print to.

The stream of bytes that Windows sends to the printer very rarely reflects the characters that are being printed. For example, if you put "Hello, World" in notepad and print it, the resulting byte stream to the printer will far exceed the 12 characters you typed.

Are you trying to catch the byte-stream or the characters?

Murtan 317 Practically a Master Poster

Short answer:

Move the do { from line 23/24 in front of the random stuff starting on line 15.

Longer answer:
If you were to break each problem type out into a function, you could call it from the if (choice == stuff. The function could then generate the random values for the problem.

This second method would have the added advantage of having everything about the problem all in one place. (The random parameters, the display, the input and the validation.) Also, your code wouldn't be bothering to generate random problems that will never be used.

Sample add method:

void add()
{
   int add1 = (rand()%500)+1;
   int add2 = (rand()%500)+1;
   int addAnswer = add1 + add2;

   cout << setw (6) << add1 << "\n";
   cout << "+ ";
   cout << setw (4) << add2 << "\n";
   cout << "------";
   cout << "\n";
   cin >> input;
   cout << "\n";
   if (input == addAnswer)
      cout << "Congratulations\n";
   else
      cout << "That is incorrect,\nThe correct answer is: " << addAnswer;
   cout << "\n";
   cout << "\n";
}
Murtan 317 Practically a Master Poster

When I was testing the deck, I put in a couple of helper functions and just put the play in main.

You should probably have one method to play a hand or round, which will include dealing, hit/stay, dealer hit/stay and scoring. Whether you put those directly in the method or in other methods called from there is mostly a matter of preference. (Unless something gets really big, then you're almost always better of breaking it up.)

Another method might 'sequence' the hands and determine if the user wanted to keep playing, but that's just my take on it; there is no 'One True Way' to write it.

The class should probably also keep track of the number of hands won vs the number of hands lost.

Murtan 317 Practically a Master Poster

You entered tried_good = ( ) did you mean tried_good = 0 ?

Repeat above comment for tried_bad as well.

You have 2 while loops with neither while really meeting your goal. I think you'd be better off with a for loop, prompting for letter guesses. Then use an if to display whether or not the letter guess was in the word.

When the for loop runs out, they have used all of their letter guesses and will have to guess at the word.

for guesscount in range(1,6):
        lguess = raw_input("Enter your letter guess #%d" % guesscount)
        # put an if test here along with the 'yes' or 'no' display
    # They've run out of letter guesses
    guess_word = raw_input("What do you think the word is? ")
    # test and output here
Murtan 317 Practically a Master Poster

Multiple exit points means there is more than one way out of the function. (Each 'return' statement is an exit point.)

I think you want to have the BlackJack class create a DeckOfCards; something like [/icode]self.deck = DeckOfCards()[/icode] then you can do things like self.deck.mix()

Murtan 317 Practically a Master Poster

ALWAYS use CODE tags when posting code. Also all of the leading whitespace is missing from your posted code. In python, leading whitespace is an essential part of your code, you can't compile without it.

(I was going to re-post your code here with the code tags, but I don't feel like taking the time to put all the whitespace back.)

If you have read from a text file and you find the strings have the \n at the end, you can remove it using a slice.

myline = infile.readline()
fname = myline[:-1]

The myline[:-1] will return all but the last character from myline.

You went to the trouble of writing the Student class, why are you replicating all of the data in the lists? (ListF, ListL, ListT, ListC, ListQ)

Why not add a 'display' or 'dump' method to the Student and then print that for debug?

Murtan 317 Practically a Master Poster

Please use the CODE tags around anything that is a block of code, it makes it easier to read.

#define API_DLLEXPORT extern "C" __declspec(dllexport)
HINSTANCE hIQ_Measure; // handle for IQ_Measure DLL
hIQ_Measure = LoadLibrary("IQ_Fact.dll"); // you only need to do this once
typedef IQ_RESULT_TYPE *(*DLL_PROC)( LPTSTR);
typedef IQ_RESULT_SWEEP_TYPE *(*DLL_SWEEP_PROC)(LPTSTR);
typedef LOG_RESULT_TYPE *(*DLL_LOG_PROC)(char *);
API_DLLEXPORT bool LabV_IQ_verify_TX_EVM ( char *sPara, int *pass,
int *num_results, char *description, char *test_name, char *result_text,
int test_result_pass[], double test_limit_upper[], double test_limit_lower[], double test_measure[] )
{
bool error=false;
IQ_RESULT_TYPE *ret;
DLL_PROC call;
int TestItem;
// obtain_control Dll Fuction
call = (DLL_PROC) GetProcAddress ( hIQ_Measure, "IQ_verify_TX_EVM" );
ret = call ( sPara );
// Move the structed data to return native data types.
if (ret->error_occur_flag)
error=true;
Transfer_struct_to_native_datatypes ( ret,
pass, num_results, description, test_name, result_text,
test_result_pass, test_limit_upper, test_limit_lower, test_measure );
return (error);
}

If you're getting any error message (compile or runtime), the actual error text would be useful.

The 'LoadLibrary' call is usually made from within a code block and not as part of global initialization. It would allow you to test for success or failure of the call.

(I'm pretty sure that calling LoadLibray to initialize a global variable is also bad form, but I'm willing to be corrected.)

If you have an error, do you still want to call Transfer_struct_to_native_datatypes ?

The code 'as written' appears to be intended as a DLL to be loaded by another application. (LabView maybe?) You will need to make sure your development environment is setup …

Murtan 317 Practically a Master Poster

LPT1 is a device, you are unable to open it to read what someone else has written (or will write) to it, it just doesn't work that way.

To do what you are proposing, you would need to somehow 'get between' the other application and the output device. You could then log the characters the other application sends and forward them to the device.

Murtan 317 Practically a Master Poster

Your loop starting on line 129 is only one line long (130)

You should probably also indent lines 131 to 147 to the same level as 130 to make them part of the loop.

Murtan 317 Practically a Master Poster

Not to be too terribly picky, but the code in the above post where it uses if int(num) not in [0,1]: will fail if the user enters non-digit characters.

If the test were performed with strings it would not fail: if num not in ['0','1']:

Murtan 317 Practically a Master Poster

I don't know what your problem is in particular, but it may be that you need to allow autocad some time to process the first command before it is ready to accept the second command.

Alternatively if you are using OLE or COM to interface with AutoCAD, you need to follow their conventions. Do you need to request status or completion status after you send the command before you can send another command?

It appears that you are using a keystroke driven interface for at least part of your control. I can't tell if SendCommand is a keystroke interface or an OLE interface, but I know SendKeys is a keystroke interface.

If SendCommand is not a keystroke interface, it would probably be in your best interest to pick a SINGLE method of interaction with AutoCAD and not try to mix metaphors.

If you are using a keystroke interface, I recall that some applications like to 'clear the keyboard buffer' prior to prompting for a new command. If AutoCAD is written this way, you will need to make sure you are not sending keystrokes to AutoCAD until it has re-prompted for a command or they will be discarded.

See if any of the above gives you a new way to look at your problem.

Murtan 317 Practically a Master Poster

You don't want the for in the cardValue method.

You also can't compare against 3 string values with elif c[:-1] == "J" or "K" or "Q": you either need to change it to elif c[:-1] == "J" or c[:-1] == "Q" or c[:-1] == "K": or to elif c[:-1] in ["J","Q","K"]: cardValue is only trying to get the value for a single card.
handValue uses it to help calculate the value for the hand.

Here's a version without the for loop and just returning the card value when it knows what it is. (Note this has multiple exit points, which can be bad form, but in this case I would do it anyway.)

def cardValue(card):
    if card[:-1] == "A":
        return 11
    if card[:-1] in ["J", "Q", "K"]:
        return 10
    return int(card[:-1])

Once you get it working, the handValue method will call cardValue to get the value for each card.

Murtan 317 Practically a Master Poster

Stock would normally be the 'on hand quantity' of an item. (In this case a book title.) A related concept is Stocking Level which is the amount of an item that we would like to keep 'on hand'.

Stock could be an attribute of a book title, but not of a particular book. So the answer depends somewhat on your ERD.

If a record in book represents a particular physical book (i.e. if you have 3 copies of 'War and Peace' you have 3 records so that you can represent where each of the copies are) then stock cannot be an attribute of book, and will likely be an entity.

If instead a record in book represents a particular title and the shelf has a record for each book located there, then you can make stock an attribute of book.

Murtan 317 Practically a Master Poster

I'm not certain I understand your question or what you need help with. (Specific questions usually get faster and better answers.)

Are you saying that you need to write an application that will be run weekly to extract data from an Excel worksheet and insert it into an SQL database?

The application should also display the data that it is adding (or did add) to the database in a datagrid so the user can view it?

Does the datagrid view need to happen before putting the data in the database? (Is it some form of verification step?)

How does the application know where to find the Excel worksheet?

What data from the Excel worksheet needs to be added to the database?

I suspect that your application will be using COM automation to have open Excel and read the data from the worksheet. (I've done this from Python quite effectively and it should be easier in C#)

You then load the data you extract into the datagrid.

Once the user 'approves' the data, you would generate SQL statements to insert or update the data in the database.

Based on the given information that's about all I can come up with.

If you want more assistance, show us what you have done, or what you're having problems with.

Murtan 317 Practically a Master Poster

If you want help (with what obviously appears to be homework) show us what you have so far. We will usually help you with homework, but we won't do it for you.

Murtan 317 Practically a Master Poster

Your approach to getting the card number is pretty good, but it will fail for the 10 card (you'll get the value 1). You could fix what you have by doing int(card[:-1]) . The code also doesn't handle the ace yet either.

Another option to using the slice (that's what the card[:-1] is) would be to change the representation of the cards in the deck. When making the cards in the deck of cards, instead of making a single string with the card and the suit, you could split them into a tuple. Where we have card + suit in the DeckOfCards. __init__ you could put (card,suit) . Each card then would be a tuple (sort of like a list, but you can't modify it) where card[0] would be the card's face value and card[1] would be the suit. If you do this, you would have to merge them when you display the cards with either card[0]+card[1] or ''.join(card) {I love how there is always more than one way way to do something, don't you} use the way that makes the most sense to you.

Ok having said the above, the way I would address the hand value would be something like the following. (I'll leave the writing of cardValue(card) to you.)

def handValue(hand):
    cardValues = []
    for card in hand:
        cardValues.append(cardValue(card))
    while sum(cardValues) > 21 and 11 in cardValues:
        cardValues.remove(11)
        cardValues.append(1)
    return sum(cardValues)

Note that this was written, expecting cardValue and handValue to be stand alone …

Murtan 317 Practically a Master Poster

Sorry it took so long to reply, but it would have been longer if I could sleep (grin).

Your current problem is that you can't create a DeckOfCards with a = DeckOfCards you need to a = DeckOfCards() If you want, you can stop reading here and go try that, it will make a world of difference.

Here's the little test app I wrote up to build the deck with more of what I had in mind. You seem to keep thinking of the cards in terms of their value to blackjack. What if you wanted to use the deck to play poker, or cribbage? This implementation will be slightly harder to score, but if I can score my hand in my head, why can't the computer?

import random

class DeckOfCards:
    def __init__(self):
        self._cards = []
        for suit in ["S","C","H","D"]:
            for card in ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]:
                self._cards.append(card+suit)
        self._drawIndex = 0

    def mix(self):
        random.shuffle(self._cards)
        self._drawIndex = 0

    def draw(self):
        rval = self._cards[self._drawIndex]
        self._drawIndex += 1
        return rval

if __name__ == "__main__":
    thedeck = DeckOfCards()
    thedeck.mix()

    playercards = []
    dealercards = []

    playercards.append(thedeck.draw())
    dealercards.append(thedeck.draw())
    playercards.append(thedeck.draw())
    dealercards.append(thedeck.draw())

    print playercards
    print dealercards

The if __name__ == "__main__" is how I'm currently adding test code to modules. This expression will be true if this file is the 'main' file, but it will be false if this file was included due to an import command.

You may also note that I didn't use the same style of import for random that you did. You …

Murtan 317 Practically a Master Poster

This program appears to be a merge of the 'have the computer pick a word and have the user guess it' and your 'number guessing' program.

As written, the user doesn't have any interface to ask if the word contains a letter. You let them guess at the word and tell them if the word is what they guessed, or if it comes alphabetically before or after their guess.

The message 'Lower Letter' which means the computer's word would appear before the word the player guessed in the dictionary and the message 'Higher Letter' which means the computer's word would appear after the word the player guessed are not very intuitive.

Before you go writing a bunch of code, plan how you think the user might interact with a program that worked like what you describe.

How does the user specifiy they are guessing a letter or if they are guessing the word?

How does the program tell them whether or not the letter is in the word?

How does the program tell them how many more letter guesses the player has?

Can the player make more than one guess at the word?

Does the game play more than once, or does it quit and the user has to re-start it to play again?

If you better define how the user will interact (which in turn describes how your program must behave) you'll have a much better idea of where to …

Murtan 317 Practically a Master Poster

Yes the code can all be in one file, but you still have to end up defining the objects (classes) and how they interact. The multi-file method would make more sense if you planned to re-use some of the classes.

For example, the 'deck of cards' would probably populate itself when you make it, support a 'shuffle' or 'mix' method to mix all the cards up. It would probably have a 'deal' method that would return the next card from the deck and maybe a counter to tell you how many cards are left in the deck. You could then re-mix the cards every hand or every few hands without having to worry about the deck anymore.

The game would interact with the deck by calling mix and then deal to get a card for the player. Then deal for the 'down card' for the dealer. Then calling deal twice more to get the player's second card and the 'up card' for the dealer.

Is this how you think of the problem, or do you think about it some other way?

NOTE: this is the key part of the problem (or assignment) how do YOU think about the problem? How do you think about breaking the problem up into smaller, more-managable pieces?

What else would be required to complete a round of play?

How does the user (player) decide to keep playing or to quit?

I am intentionally asking leading questions to help …

Murtan 317 Practically a Master Poster

You're using 'choice' from the random module. This selects a random member of the list. This part is ok, but if you were to give the cards actual display values (like 5S for 5 of Spaces or 2H for the 2 of Hearts) nothing in choice prevents you from dealing the same card twice, its always picking a card from a new deck, regardless of the cards that have already been drawn.

I like the concept of a deck of cards as a class, but the deck of cards shouldn't know anything about the player or the computer or the score or anything besides the cards. That data should live in another class or as global data, depending on your design.

(Side note: if you build a list of cards you could use random.shuffle to mix up the order of the cards in the list. Then you could 'walk through' the list from head to tail to get cards which would guarantee you didn't deal the same card twice.)

Why do you limit the user to only being able to hit when the total is 18 or less? Granted it wouldn't be very common to hit at or above 18, but I think it is the player's decision to make.

You might consider a 'card' class that has a display (like AD, 7C, JS) and a value. (Right now your deck is only values.) This might make it easier to 'score' a hand. The problem being …

Murtan 317 Practically a Master Poster

What's your objective?

What kind of interface do you need? Should the game play fully automated, or does the user interact with the game? If fully automated, where/how do you define the 'rules' for the player?

Do you need to shuffle the deck?

What keeps 'choice' from re-picking the same card that was picked previously?

When dealing Blackjack, don't you normally deal one to each player and then one to the dealer. Then repeat for the second card?

Murtan 317 Practically a Master Poster

I think for testing your example, you could ignore the 'bad form'.

But if this will be accessed by other people (especially the public) that might ever have malicious intent then you should address this and any other code that might be subject to attack.

For more information on protecting yourself from SQL Injection attacks, I recommend the following article:

http://msdn.microsoft.com/en-us/library/ms998271.aspx

Murtan 317 Practically a Master Poster

I tried to say it before, but you didn't appear to understand.

You CAN NOT foreach over arr3 inside the if match

foreach $str1(@arr1)
{
   for (my $ii=0; $ii< scalar(@arr2); $ii++)
   {
      $str2 = $arr2[$ii];
      if($str1=~/$str2/)
      {
         print "<br> matched <br>";
         # at this point, we just replace $str1
         # with the string in @arr3 at the same index
         # as the string we just matched from @arr2
         $str1 = $arr3[$ii];
         # note that this actually updates the data in @arr1
      }
   }
   print "<br> *** $str1 <br>";
}

Note that we are still iterating over ALL of the lines in arr2 for EACH line in arr1. This would allow us to match the strings from arr2 more than once. I don't know if this might be an issue, either from a correctness or a performance standpoint.

Note also that the test condition $str1=~/$str2/ allows for partial matches. If the string in $str2 is found anywhere in $str1, the entire $str1 is replaced with $str3. This was also true in your original code.

Murtan 317 Practically a Master Poster

I've been playing with the algorithm I proposed and I've come to the conclusion that you can't 'progressively' validate. At least not without some provision to 'go back and try again'.

I've been having my suggestion get stuck when it painted itself into a corner. (For example on one run, a valid block of 9 needed the lower right corner be 4 to be successful, but the value 4 was previously used in that column. ) In order to complete, it would necessarily have to revisit at least previous columns, if not previous rows as well.

Murtan 317 Practically a Master Poster

I think the problem is where you're building your select

SqlDataAdapter da = new SqlDataAdapter("select * from mudiamINC where fname like" + TextBox1.Text + " %", con);

I'm think you need a space after the like, but not before the %

SqlDataAdapter da = new SqlDataAdapter("select * from mudiamINC where fname like " + TextBox1.Text + "%", con);

Note however that I suspect this code is 'bad form'. You are taking user input without validation and putting it into SQL queries. This potentially puts your application at risk for SQL injection attacks.

Murtan 317 Practically a Master Poster

I believe your algorithm is the source of your problem...you are running 3 nested loops, when I think your intent is to iterate at least some of the arrays simultaneously.

Your algorithm (as written) does the following:
For each row of the first array, compare it with each of the rows from the second array. (Note this not comparing relative rows, but all rows). Then if ANY row from the second array matched, replace the contents iteratively with all of the data from the third array (ending naturaly with the last entry in the third array).

I think the piece you are missing is that you don't want to iterate through all of the rows in the third array, you just want the row in the third array that is in the same position as the row you matched from the second array.

If you want more help, a 'bigger picture' of what you're trying to accomplish might be useful.