woooee 814 Nearly a Posting Maven

In fact, I had this lying around. Pretty basic but should give you an idea.

class Class1 :
   def __init__ (self) :
      self.field1 = "***"
      self.field2 = 0
      self.field3 = "EMPTY"

#==========================================================================
ctr = 0
class_dic = {}

C = Class1()
C.field1 = "Test1"
C.field2 = 1
C.field3 = "Test1A"
class_dic[ctr] = C
ctr += 1

C = Class1()
##C.field1 = "Test2"
C.field2 = 2
C.field3 = "Test2A"
class_dic[ctr] = C
ctr += 1

C = Class1()
C.field1 = "Test3"
C.field2 = 3
##C.field3 = "Test3A"
class_dic[ctr] = C

class_dic[1].field3 = "ID test"

for D in class_dic :
   print D, class_dic[D].field1, class_dic[D].field2, class_dic[D].field3
woooee 814 Nearly a Posting Maven

You would generally use a dictionary for this (and please do not use "l", "i", or "o" for single digit variables--they look too much like numbers). The dictionary key would point to a list ["abstract", "title", "ID"]

class classic:

   def __init__(self,text):
      text ="TI -xxTI -yy TI -z"
      self.class_dic = {}
      for  r in range(text.count('TI -')):
         self.class_dic[r] = ["empty", "empty", "empty"]

      ##   change the "ID" (element 2) for key=1
      self.class_dic[1][2] = "ID test"
      print self.class_dic

If you really want to use a class for abstract, title, and ID, then the dictioary key can point to a class instance instead of a list.

woooee 814 Nearly a Posting Maven

It is more common to iterate the file one record at a time instead of the read() and split().

import random

outfile = open('numbers.txt', 'w')
for count in range(20):
        ##Get random numbers
        rebmun = random.randint(1,99)
        outfile.write(str(rebmun) + '\n')
outfile.close()

numbers={}
fp = open('numbers.txt','r')
for rec in fp:
        numbers[rec.strip()] = "test"
print numbers
woooee 814 Nearly a Posting Maven

If you do not understand the shorthand version in Gribouillis' code, it is the same as

def addbook(ISBN, author, title, stock):
    if ISBN in bookdic:
        ## booklist[ISBN][2] += stock
        ISBN_list = bookdic[ISBN]   ## returns the list for this key
        print ISBN, ISBN_list
        ISBN_stock = ISBN_list[2]
        ISBN_stock += stock
        ISBN_list[2] = ISBN_stock
    else:
	bookdic[ISBN] = [author, title, stock]

As you can see, the original code is much simplier once you understand it.

woooee 814 Nearly a Posting Maven

You return the string "error". It is an empty string unless the following is true.

for element in find_text(item):
    if extra+element.tag.replace(' ','') in Results[0].keys():
        if element.text >= Results[0][extra+element.tag.replace(' ','')]:
            error = error + "Error with "+item.tag+" "+element.tag+" value = "+element.text +" \n"
              
    else:
        continue
woooee 814 Nearly a Posting Maven

Whatever you decide, jump in and try it. You will have to post some code if you want any specific help.

woooee 814 Nearly a Posting Maven

Using an SQLite database is the simpliest and best. It comes with Python and a tutorial is here http://www.devshed.com/c/a/Python/Using-SQLite-in-Python/

woooee 814 Nearly a Posting Maven

This will only execute actionDefault once.

do_action = 0
if testA:
  actionA()
  if testB:
    actionB()
    if textC:
      actionC()
    else:
      do_action=1
  else:
    do_action=1
else:
  do_action=1
if do_action:
  actionDefault()
woooee 814 Nearly a Posting Maven

I just happen to have it handy:

We all have interesting little snippets lying around. Too bad we can't find some way to create some sort of central index, but it is more than I have time for.

Image Files
     tif to gif
SQLite
     database - create
     database - modify record
Homework problems
     common
          primes - find all up to a certain number
etc.
woooee 814 Nearly a Posting Maven

I want the program to say that after the first year the value would be(50*1.05=52.5) and the second year would be (50*1.05^2+52.5=107.625)

That does not appear to be correct IMO. In the second year you have the same $50 drawing interest twice for the first year, once in the $52.50 and once in the $50*1.05^2. You have $50.00 that will be paid interest every year
$50 * 1.05 over some range of years
or you will have accumulated interest
new_principle_interest * 1.05 (or += .05) over some range of years.

and the third year would be (50*1.05^3+107.625=165.50625)

If $50 is deposited every year, which I did not see in the original problem, then this is still incorrect as each $50 would only earn interest from the time it was deposited. First get the math down and then worry about converting it into code.

woooee 814 Nearly a Posting Maven

I want the program to say that after the first year the value would be(50*1.05=52.5) and the second year would be (50*1.05^2+52.5=107.625) and the third year would be (50*1.05^3+107.625=165.50625)

That does not appear to be correct IMO. In the second year you have the same $50 drawing interest twice for the first year, once in the $52.50 and once in the $50*1.05^2. You have $50.00 that will be paid interest every year
$50 * 1.05 over some range of years
or you will have accumulated interest
new_principle_interest *= 1.05 (or += .05) over some range of years. First get the math down and then worry about converting it into code.

woooee 814 Nearly a Posting Maven

Python has the built in isupper() and islower() (also isdigit, isspace, ispunct) http://www.python.org/doc/2.5.2/lib/module-curses.ascii.html

test=["AabcdEFg.",
      "jKLmnopR?" ]
      
upper_total=0
lower_total=0
neither_total=0
for rec in test:
   for chr in rec:
      if chr.isupper():
         upper_total += 1
      elif chr.islower():
         lower_total += 1
      else:
         neither_total += 1

print "%d Upper Case,  %d lower case,  and %d neither" % \
      (upper_total, lower_total, neither_total)
#
# And if you wanted to go with your original idea, it would be
if (chr >= "A") and (chr <= "Z"):
   upper_total += 1
etc.

Edit: and it looks like great minds think alike.

woooee 814 Nearly a Posting Maven

I don't use this so am not sure, but you can do something along the lines of this so you have a pre-defined string instead of substitution in the SQL statement.

field_type = "TEXT"
SQL_statement = "CREATE TABLE %s (%s %s, %s %s, %s %s, %s %s, %s %s)" % \
     (t_name, field_type, \
      t_date, field_type, \
      t_explanations, field_type, \
      t_deposit, field_type, \
      t_withdraw, field_type, \
      t_balance, field_type)
print SQL_statement
cursor.execute(SQL_statement)

Note that in the example you linked in the previous post, they are using VARCHAR, which I always use, so if you get an error try changing TEXT to VARCHAR. SQLite does not support a full SQL set of statements but has most of the stuff that a normal user will use.

Edit: Doh! I have a work-in-progress program that I use to create a simple and quick database with access. I fed in your fields, and the following came out which hopefully should help some. It sould be trivial to pass the database's name to the class as a variable or change the number of fields, etc.

##======================================================================
class DummyClass:
   def __init__( self ) :
      self.SQL_filename = './test_dbf'
      self.open_files()

   ##   END  __init__()

   ##----------------------------------------------------------------------
   def add_rec( self ) :
      val_tuple=(self.t_date, self.t_explanations, self.t_deposit, self.t_withdraw, self.t_balance)
      self.cur.execute('INSERT INTO test_dbf values (?,?,?,?,?)', val_tuple)
      self.con.commit()

   ##   END  AddRec()

   ##----------------------------------------------------------------------
   def copy_to_struct( self, rec ) :
      self.t_date = rec[0]
      self.t_explanations = rec[1]
      self.t_deposit = rec[2]
      self.t_withdraw = rec[3]
      self.t_balance = rec[4]

   ##   END  copy_to_struct()

   ##----------------------------------------------------------------------
   def list_all_recs( self ) :
      self.cur.execute("select …
woooee 814 Nearly a Posting Maven

You have to give each field in the SQLite db a name so you can access each one individually, and define it as a variable length character field, integer, etc.. Select where sql_date == date_today kind of thing. Assuming that everything is a string...

## Create a connection to the database file
con = sqlite.connect('test_db')
## Get a Cursor object that operates in the context of Connection con
cursor = con.cursor()
 
cursor.execute('''create table test_db(sql_date varchar,sql_exp varchar, sql_deposit varchar, sql_withdraw varchar, sql_balance varchar)''')

val_tuple=(t_date, t_explanations, t_deposit, t_withdraw, t_balance)
cursor.execute('INSERT INTO test_db values (?,?,?,?,?)', val_tuple)
con.commit()
woooee 814 Nearly a Posting Maven

I would like to know if there is an easier way than what I just did

Would raise red flags for a beginning homework assignment like above, but you can use operator to sort on any list element

import operator

data = [
'kick me 989',                                              
'bodybody 344',
'Santa Clause 0943',
'Bart Simpson 100', 
'As Is 2856' ]

##  sort on last element
data_as_lists = [ rec.split() for rec in data ]   ## convert into list of lists
data_as_lists.sort(key=operator.itemgetter(-1))
print data_as_lists
print
for each_rec in data_as_lists :
   print each_rec

## or, using integers
for rec in data_as_lists:
   rec[-1] = int(rec[-1])
data_as_lists.sort(key=operator.itemgetter(-1))
print data_as_lists
print
for each_rec in data_as_lists :
   print each_rec
woooee 814 Nearly a Posting Maven

printB is not part of the class unless you define as being a class member, like so

def printB(self):
         print "B"

You then call it with
self.printB()
See this page from "How To Think Like A Computer Scientist" http://www.greenteapress.com/thinkpython/html/book018.html

woooee 814 Nearly a Posting Maven

it now makes the last word the longest?

Add some print statements and you should be able to see what is going on.

for word in splicedsent:
    print "\ncomparing word %s, length=%d, longest=%s" % \
             (word, len(word), longestLength)
    if len(word) > longestLength:
        longestword=word
        print "length > longest is true"
woooee 814 Nearly a Posting Maven

return' outside function line 35.
What does that mean?

You have a "return" statement outside the confines of a function. Which is correct. There is no function definition in your program, and you can't do a function return from no function.

woooee 814 Nearly a Posting Maven

You don't have to use a tuple to store the guesses. A list is normally used, but you can also use a string thusly (this is not meant to be a complete solution)

guess_word = "alfalfa"
correct_guess = ""
wrong_guess = ""
previous_guesses = ""
                                                                              
## generate a list to test with instead of input
tries = [ "a", "b", "e", "a", "o" ]
for guess in tries:
   if guess in previous_guesses:
      print guess, "has already been guessed"
   elif guess in guess_word:
      print guess, "is correct"
      correct_guess += guess
   else:
      print guess, "is NOT correct"
      wrong_guess += guess
   previous_guesses += guess

Also, I prefer to use a function, and return at a breakpoint. Perhaps that will be easier to get your head around.

def guess_word(random_word):

   guess_count = 0
   correct_guess = ""
   wrong_guess = ""
   previous = ""

   while guess_count < 6: 
      guess_count+=1
      guess=raw_input("\nguess one letter ")

      if guess in previous:
         print guess, "has already been guessed"
         guess_count -= 1         ## don't charge for duplicate guesses
      elif guess in random_word:
         print guess, "is correct"
         correct_guess += guess
      else:
         print guess, "is NOT correct"
         wrong_guess += guess
      previous += guess
      ##---   while testing, check that this works correctly
      print correct_guess
      print wrong_guess

   print len(correct_guess), "correct guesses and", len(wrong_guess), "incorrect"        

   ##---  This is the return part                               
   while 1:
      print  "You have to guess the word now"
      guess_word=raw_input("What say you (hit Enter to quit) ")
      guess_word = guess_word.strip()
      if len(guess_word) == 0:   ##  Enter key only
         return
      elif guess_word.lower() == random_word:
         print …
Murtan commented: I like your solution, I was just hoping to encourage the OP to do more +1
woooee 814 Nearly a Posting Maven

Your last 2 lines would be modified thusly

primeNum = int(raw_input("Enter number here:"))
prime_list = listfactors(primeNum)  ## your function returns a list
for prime in prime_list:
    print "prime =", prime

Also, a second for using modulo or divmod. Your function compares integers and floats and you will be comparing numbers like int=1, and float=0.99999 because of the nature of using floats which will always test false. Hopefully you are only testing integers for "primeness" and so should work with integers only. Finally, it is bad form to use "i", "l", or "o" as single letter variables, as they look too much like numbers.

woooee 814 Nearly a Posting Maven

Assuming that the server belongs to your ISP, you want to first ask them if Python is supported. It usually is, and they probably have some examples of the types of things they allow. Unlike using IDLE, the program file would be run from the command line or another program and how you do that would depend in part on which operating system you are using. This is the web programming page on the Python Wiki (and may be more than you want right now) http://wiki.python.org/moin/WebProgramming

vegaseat commented: thanks for the info +11
woooee 814 Nearly a Posting Maven

I've flagged this as a bad post. Since this is the first time, hopefully it was done correctly. This was the message:

This post is from someone who posted a link to their homework assignment, with no attempt to code anything themselves, and then asked for the answer. Further, they berate someone for not reading the homework assignment completely. Any one who is too lazy to cut and paste the question into the forum should not criticize someone else. We don't want to encourage the attitude of, "I'll sit here on the veranda in my rocking chair while you go fetch the homework from the web for me, and then code the answer while I sit here rocking away". Obviously, this violates the "only help those who shown some effort" and also violates the "keep it pleasant" guidline.

woooee 814 Nearly a Posting Maven

If it is easier to get your head around, you can use a dictionary of lists, with the dictionary key as the row number, each containing x columns. You could also take this one step further and use a dictionary of dictionaries with row and column number as keys.

def populate_array(rows, columns):
   array_dic = {}
   for row in range(1, rows+1):     ## starts with one, not zero
      array_dic[row] = []
      for col in range(0, columns):
         array_dic[row].append('None')     ## initialize to 'None'
   return array_dic
   
if __name__ == "__main__":
   rows = 10
   columns = 5
   ret_dic = populate_array(rows, columns)
   for key in ret_dic.keys():
      print key, ret_dic[key]
      
   ##---  change some value
   row = 3
   col = 1
   ret_dic[row][col] = 'Changed'
   print "\n"
   for key in ret_dic.keys():
      print key, ret_dic[key]
woooee 814 Nearly a Posting Maven

Note the last line

_mysql_exceptions.ProgrammingError: (1146, "Table 'router.table_name' doesn't exist")

It is looking for "table_name" not the contents of the variable. So you want to insert the actual name which can be done in a number of ways along the general line of the following. This is just your statement with one extra "%s" added for the table_name. It is not tested, and I don't use MySQL, but the principle should work.

SQL_statement = 'INSERT INTO %s(device_name,event_date,event_time,event_action,event_protocol,event_src_ip,event_src_port,event_dst_ip,event_dst_port,event_num_pckts) VALUES ("%s","%s","%s","%s","%s","%s","%s","%s","%s","%s")' %
(table_name,vice_name,event_date,event_time,event_action,event_protocol,event_src_ip,event_src_port,event_dst_ip,event_dst_port,event_num_pckts) 

print SQL_statement  ## examine for correctness
q.execute(SQL_statement)
woooee 814 Nearly a Posting Maven

See the last post here for the general idea http://www.daniweb.com/forums/thread158680.html You want to use some variable in a while loop that you can set to false if (1) the correct word is guessed, (2) the maximum number of guesses is reached, (3) any other exit criteria. You can also use a function and return on any of the above.

woooee 814 Nearly a Posting Maven

Ran the program computer outputs 10 random words.

That's all the program was supposed to do. Now you will have to tell the user the number of letters, use a loop to ask for guesses, and compare to letters in the word with the appropriate correct/incorrect response.

woooee 814 Nearly a Posting Maven

Instead of the seek method, you could also use a dictionary to assign a number to each word, and then pick a random integer and print the word associated with that integer. IMHO it is preferable to use numbers whenever possible as that is the native language of the computer.

from random import randint
   
def read_file():
   words = {}
   ctr = 0
   dic_path="/usr/local/DictionaryE.txt"
   fileptr =open (dic_path ,"r")
   for rec in fileptr:
      words[ctr] = rec.strip()
      ctr += 1
   fileptr.close()
   return words


if __name__ =="__main__":
 
   word_dictionary = read_file()
   limit = len(word_dictionary) - 1

   n =10
   print "%d randomly generated words from a list of %d\n" % \
         (n, limit)
 
   for i in xrange (n ):
      offset = randint (0, limit )
      word = word_dictionary[offset]
      print offset, word
   print
woooee 814 Nearly a Posting Maven

I use a class 99% of the time. Once the program gets beyond the simple function level, it organizes the code IMHO. Also, a class doesn't have any of the global variable problems.

woooee 814 Nearly a Posting Maven
binary = int(raw_input("Enter a binary number:"))
for i in range(binary):
    print "for loop is testing", i, "in range", binary
    if (binary != 0 or binary != 1):
        print binary, "not equal to 0 or 1"
        binary = int(raw_input("Enter a binary number:"))
    else:
       print binary, "equal to 0 or 1"
woooee 814 Nearly a Posting Maven

But now I want to be able to save it in file, preferably in form like this:

number;name

It's a simple combination so a common text file will work just fine. There is also the advantage of being able to verify what you have written to the file via any text processor. Note that dictionaries hash keys so they are not necessarily in key order.

def read_from_file():
   after_d = {}
   fp = open("test.txt", "r")
   for rec in fp:
      rec=rec.strip()
      key, name = rec.split(";")
      after_d[int(key)]=name        ## convert key back to an integer
   fp.close()
   return after_d


def save_to_file(save_d):
   print "before saving to file", save_d
   fp = open("test.txt", "w")
   for key in save_d.keys():
      fp.write("%d;%s\n" % (key, save_d[key]))  ## writes everything as a string
   fp.close()
   

before_d = {}
before_d[1]="Name 1"
before_d[2]="Name 2"
before_d[3]="Name 3"
before_d[10]="Name 10"
before_d[20]="Name 20"

save_to_file(before_d)
after = read_from_file()
print "read from file       ", after
woooee 814 Nearly a Posting Maven

You're making it too difficult. Store the previous record in memory.

prev_line = ""
for line in infile:
     linesplit = line.split(",")
     line = line[:-1]

     if line startswith("Line"):
           write stuff
     if line startswith("$GPGGA"):
          calculate and write stuff
     if line startswith("EOL")
          outfile.write("%s\n" % (prev_line))   <==========
     ##  copying = last thing in this loop
     prev_line = line                              <==========
woooee 814 Nearly a Posting Maven

You don't initialize Total2 to zero for each run through the outer loop

#sum each 5 fields over the raw:
    for step in range (6, N, 5):
        Total2=0     <--------------------------
        for i in range (step-5, step, 1):
            Total2 += float(fields2[i])
            # do something
                     
        print i, step, Total2
woooee 814 Nearly a Posting Maven

The easiest way to understand it is to break each part down and give it a separate variable name.

"""      
dictFoldersNew = {"A":{"XYZ": [["Name1", "UID1"], ["Name2", "UID2"]],
"PLM": [["Number1", "UUID1"], ["Number2", "UID2"]],
"RST": [["ID1", "UUID1"], ["ID2", "UID2"]]},
"B": [["IDB1", "UID1"], ["IDB2", "UID2"]],
"C": [["IDC1", "UID1"], ["IDC2", "UID2"]],
"D": [["IDD1", "UID1"], ["IDD2", "UID2"]]}
"""      

top_level = {}
top_level["A"] = {}
top_level["B"] = []
top_level["C"] = []

##---  populate "A"
level_2_dic = top_level["A"]
level_2_dic["XYZ"] = []
level_2_dic["PLM"] = []

this_list = level_2_dic["XYZ"]
this_list.append(["Name1", "UIX1"])
this_list.append(["Name2", "UIY2"])

this_list = level_2_dic["PLM"]
this_list.append(["Number1", "UUID1"])
this_list.append(["Number2", "UUID2"])

##---  populate "B"
this_list = top_level["B"]
this_list.append(["IDB1", "UID1"])
this_list.append(["IDB2", "UID2"])

##---  populate "C"
this_list = top_level["C"]
this_list.append(["IDC1", "UIE1"])
this_list.append(["IDC2", "UIE2"])

##--- print all data
for key in top_level:
   print key
   if type(top_level[key]) is dict:
      level_2 = top_level[key]
      for sub_key in level_2:
         print "     dictionary", sub_key
         this_list = level_2[sub_key]
         for each_list in this_list:
            print "          list", sub_list
   elif type(top_level[key]) is list:
      print "     list"
      this_list in top_level[key]:
      for each_list in this_list:
         print "          list", sub_list
   print
   
##  you can also do this
print top_level["A"]["XYZ"][0]   ## first list in "XYZ" in "A"

You want to get away from the word processing thought pattern, where you have lines in documents in folders. None of that really exists. With programming you have one continuous stream of bytes, either in memory or on disk. Then you have pointers to the memory/disk location. So, you want to access the pointer to "A" and access the bytes at that location which gives the pointer to …

woooee 814 Nearly a Posting Maven

The python.org website has a beginners guide that includes links to tutorials and introductory books. http://wiki.python.org/moin/BeginnersGuide

woooee 814 Nearly a Posting Maven

Thanks Gribouillis. I didn't know about bisect.

woooee 814 Nearly a Posting Maven

Definitely use a dictionary or SQL database if there are a lot of entries. It is hundreds or thousands of times faster depending. The time consuming part of the code is looping through the list twice. Using a try/except to check the list once with no "in" statement is a workaround, but just a workaround and not better than using a dictionary. As for checking letter by letter, that's what the existing or any compare/find/index has to do. There is no way to find something comparing an entire word to an entire word. The only shortcut that I know of would be to group words according to length. Thus, a five letter word would only look at other 5 letter words, and not words of other lengths.

##if wordq in  a:     ## omit this line - duplicate list checking
try:
   c = a.index(wordq)
   print wordq
   print
   print b[c]
except:
   print wordq, "wasn't found in 'a'"

Edit: There is also sets if dictionaries are more than you want to do at this time. Both dictionaries and sets use a hash as an index, so the execution times should be similiar for both.

list1 = ['a', 'b', 'c', 'd']
list2 = ['b']
set1=set(list1)
set2=set(list2)
set3= set1.intersection(set2)
print "set3 =", set3

set5=set(["z"])
set6=set1.intersection(set5)
print "set6 =", set6
woooee 814 Nearly a Posting Maven

If you run the above code, it will not work as expected. You want
if shipweight <= 2: as the first if, and the following elif's should use and
elif shipweight >2 and shipweight <6:
Also, what if the weight equals 6? This code doesn't allow for that. BTW, the "standard" way of doing this kind of thing is to use a container like a list. You eliminate a long string of elif, and you can simply modify the list to add/change/delete weight catagories. (No additional elif necessary if another catagory is added.)

def shipping_charges(package_weight):
     charges_list= [ [10, '4.80'],
                     [ 6, '4.70'],
                     [ 2, '3.20'],
                     [ -0.01, '2.10'] ]
     for weight_list in charges_list:
          print "     checking", weight_list[0], "-->", weight_list
          if package_weight > weight_list[0]:
             print "found"
             return weight_list[1]

print 'Welcome to Shipping Company Rate Calculator'
shipweight=raw_input ('Please Enter the Weight of the Item You Wish To Ship: ')
try:
   weight_package = float(shipweight)
   charges = shipping_charges(weight_package)
   print "Your total shipping charges:", charges
except:
   print "You can only enter a number"
woooee 814 Nearly a Posting Maven

On Linux, you can add a path to the PYTHONPATH variable in ~/.bashrc. Add this line
export PYTHONPATH=${PYTHONPATH}:/new/path:/another/path:/colon/separates
The next time you boot, the PYTHONPATH will reflect the changes.

woooee 814 Nearly a Posting Maven

Sorry for the dumb question, I saw the problem, thanks for looking though.

They are pretty much all dumb.....after you find the answer. Also, please mark the post solved.

woooee 814 Nearly a Posting Maven

Is anyone else getting a little tired of the "I Googled it and couldn't find anything" lie. "python sum list" brings up "total = sum(list_name)" as the second hit. Searching for "python adding list" gives both the sum() and a for() loop as examples on the fourth hit. But is it a complete waste of time to call them on it? Perhaps we should start posting the Google link. I am more than willing to help anyone with a real programming problem, but this wasting everyone's time can lead to fewer programmers who help because of all of the cruft that one has to wade through.

woooee 814 Nearly a Posting Maven

I want to refer back to the previous values without having to list all of them out again

To answer your original question, you can copy a list with

orig_numbers_list=[10,13,32]
for j in range(48, 123):
   orig_numbers_list.append(j)

numbers = orig_numbers_list[:]
print "orig =", orig_numbers_list

del numbers[0]
del numbers[5]
print "\n\ncopy =", numbers

Note the "[:]". The statement "numbers = orig_numbers_list" would yield a pointer to the original list, not a copy, so changing one list would also change the other since they would both point to the same list, so "[:]" identifies a copy operation.

woooee 814 Nearly a Posting Maven

I think the way to go about this is to use modulo or divmod to find the numbers that you can divide the given number by. That is the remainder == 0. You will be working with single numbers which is less confusing. Actually, you can use the (given number / 2) since all numbers greater than the halfway point can't be divided into to the number. Then sum these numbers and see if they add up to the given number.

woooee 814 Nearly a Posting Maven

You should have also seen "Press Enter" or whatever, then you hit the Enter key, and afterwards you should see "Bye, "Bye" on the screen. If that doesn't work, I would strongly suggest reinstalling Python as it appears there is a problem. Activestate has the easiest installer for a new user IMHO. http://aspn.activestate.com/ASPN/Downloads/ActivePython

woooee 814 Nearly a Posting Maven

Run it from Idle. There is a "run" option in the menu. Idle will display the output. So enter the code in Idle, save it in Idle, click on the "run" option in the menu, and look at the output all within Idle. Finally, you can try storing your input to a variable but I doubt that will help.

print "Hello World"
x = raw_input("Press Enter")
print "Bye Bye"
woooee 814 Nearly a Posting Maven
>>> print "hello World"

raw_input("Press ENTER to exit")

That is all I have for my code

Works for me on Linux. Try

print "Hello World"
raw_input("Press ENTER to exit")
raw_input("Press ENTER to exit")
raw_input("Press ENTER to exit")

It may be that when you enter the program name on the command line, it's using that Enter for the raw input. (Being a Linux person I would just say that MS Windows is weird.) Anyway, post back with the solution if you find it. Someone else will surely be searching for that in the future.

woooee 814 Nearly a Posting Maven

First try using idle instead of Notepad. You can enter, save, and run the program from Idle. It should be under the python and then idlelib directories, and is something like Idle.py-I don't remember. That will solve the immediate problem. Your solution should work also, so it may be that it is in a part of the program that is not reached. Post the entire program if you want more info. To answer the question directly, use time.sleep(seconds)

import time
print "Starting Program"
time.sleep(2)
print "2 seconds are up already"

Edit: Here is a link to the python docs. See the "Starting IDLE on Windows" section and welcome to Python. http://www.python.org/idle/doc/idle2.html

woooee 814 Nearly a Posting Maven

x = len(matches) so when you delete a character, the length of matches is reduced but x remains the same. There are several ways to do this. The easiest would be to test for
if word.lower() in matches.lower(), but if you want to use this example then remove the del matches[c] line since it serves no purpose as far as I can tell. If that doesn't solve your problem, then post back with some sample data.

woooee 814 Nearly a Posting Maven

letters_used and wrong are never incremented. You should be able to tell that from the print letters_used statement. Also, you define letters_used=() (a tuple) and not zero.

woooee 814 Nearly a Posting Maven

Except that neither one thought to test for a < 0 (if someone doesn't know any of the words) or a => len(words). Also, you have 19 words and 20 answers. When doing this type of programming it is better to
(a) use a dictionary with the word as the key, pointing to the answer
(b) or at least test that len(words) == len(answers) especially if you are going to modify the lists at any time.

woooee 814 Nearly a Posting Maven

For future reference, it seems that matplotlib at sourceforge.net (matplotlib.sourceforge.net) would be one solution to statistical calcs like percentile and root mean square, in addition to checking the scipy programs.