woooee 814 Nearly a Posting Maven

A place to start, without coding the solution for you. Post your code for help with further problems.

main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]
for each_list in main_list:
    print "\n  New List"
    for ctr in range(len(each_list)):
        print ctr, each_list[ctr]
woooee 814 Nearly a Posting Maven

Check out ShedSkin to speed up Python code. I don't think you can learn C/C++ in the next few months, but it depends on how complicated the programs are. Some Python links
http://www.greenteapress.com/thinkpython/html/index.html
http://diveintopython.org/toc/index.html
(see "Beginner's Guide" and "Python Books") http://wiki.python.org/moin/

Gribouillis commented: shedskin looks worth trying +4
woooee 814 Nearly a Posting Maven

Duplicate post deleted.

woooee 814 Nearly a Posting Maven

What happens if you have more than one key with the same maximum? Instead of print, store the key and item if it is greater than the maximum so far.

woooee 814 Nearly a Posting Maven

You don't return or receive anything for numbers not equal to zero. The function calls itself many times. Each function call must receive the return value when the function it calls finishes, and then return that value to the function it was called by.

def recursion_test(value):
    """ recursion example incrementing a counter for each function, and
        printing each function value for that function call
    """
    print "value now =", value
    if value > 10:              ## exit recursion loop
        return value
    new_value = recursion_test(value+1)
    return new_value

print recursion_test(0)
woooee 814 Nearly a Posting Maven

Also, you can check wxpython and qt to see if they will run on Solaris. It doesn't matter which GUI toolkit you use as you can find password entry programs for any of them on the web.

woooee 814 Nearly a Posting Maven
dict={'COUNTY': COUNTY, 'TOWN': TOWN}

You should print the dictionary as it will only contain one entry. Also, do not use "dict" as a name as that is a reserved word used to convert to a dictionary. Ditto for 'locale' (instead use town_dict, etc. as it then lets the reader know what the dictionary contains).

woooee 814 Nearly a Posting Maven

I am still getting a systex error when closing the file

We can't really guess what that is. Post the entire error message. As a general rule, check that line of code and the previous for the same number of open and closing parens. If there is a paren error on the previous line, the interpreter sees the next line as a continuation line. Also, you close the file, but never open it, so that could be one of the errors.

woooee 814 Nearly a Posting Maven

Put the above code in a function and then call the function from a loop. You can use one function to get the width or the length as well by passing the maximum allowed value and the literal to print, "Width" or "Length", to the function. Note that the Python Style Guide specifies variable names and function names should be all lower case.

ask = "y"
while ask.upper() == "Y":
    calculate_costs()     ## calls above code as a function

    ask = raw_input("Would you like to calculate another ('Y' or 'N')? ")
woooee 814 Nearly a Posting Maven

Lists have min and max functions which could also be used. For both code solutions, what happens if there is more than one month with the same rainfall?

def lowest_month (rainfall):
    lowest = min(rainfall)
    return MONTH[rainfall.index(lowest)], lowest
woooee 814 Nearly a Posting Maven

Id like it to look like this Multiply ,x times ,y

See string formatting.

print "Multiply", x, "times", y
print "Multiply %d times %d" % (x, y)
woooee 814 Nearly a Posting Maven

And this will always be zero.

i=[(curletter+key)-(curletter+key)]

You can just add or subtract the shift value, depending on whether it is encrypt or decrypt, and test for < 0 or > length and add or subtract length. You can in fact use the same function for encryption and decryption by sending a switch to the function telling it which you want to do.

def do_some_testing(letter_in):
    ## decrypt = shift each letter backward by 3 letters
    letters=list("abcdefghijklmnopqrstuvwxyz")
    shift = 3 

    if letter_in in letters:
        current_location = letters.index(letter_in)
        new_location = current_location - shift
        if new_location < 0:
            new_location += len(letters)
        return(letters[new_location])
    return("*")                         ## error

##------------------------------------------------
print "z -->",
print do_some_testing("z")

print "a -->",
print do_some_testing("a")

print "-"*30
orig_string = "d txlfn eurzq ira"
decrypt_list = []
for letter in orig_string:
    decrypt_list.append(do_some_testing(letter))  
print orig_string
print "".join(decrypt_list), "\n"
woooee 814 Nearly a Posting Maven

This will never be true

if (curletter+key)>(25):
            if (curletter+key)<0:
woooee 814 Nearly a Posting Maven

You can test for membership in the rows list (already input), assuming you want to do this on the input value.

if input_num not in rows:
    rows.append(input_num)
#
# or remove each number as it is entered
input_list = [str(x) for x in range(1, 10)]
while len(input_list):
    print "Enter a number from", input_list
    num = raw_input("Enter: ")
    if num in input_list:
        input_list.remove(num)
## etc
woooee 814 Nearly a Posting Maven

You can use split() if I understand correctly.

locTextFormat = "COUNTY --- TOWN"
print locTextFormat.split("---")
##
## or is it
COUNTY = "test_county"
TOWN = "test_town"
print COUNTY + " --- " + TOWN
print "%s --- %s" % (COUNTY, TOWN)
woooee 814 Nearly a Posting Maven

Vegaseat did one a while ago and posted it http://www.daniweb.com/forums/thread198855.html I think most GUI toolkits include methods to do this.

import Tkinter as tk
 
root = tk.Tk()
 
def show_pw():
    pw = pw_entry.get()
    label2['text'] = pw
 
 
label1 = tk.Label(root, text="Enter password for user Frank: ")
# shows only * when entering a password
pw_entry = tk.Entry(root, show="*")
# cursor here
pw_entry.focus()
# click on button to show the password
button = tk.Button(root, text='show password', command=show_pw)
# label to show result
label2 = tk.Label(root)
 
# widget layout, stack vertical
label1.pack()
pw_entry.pack()
button.pack()
label2.pack()
 
# start the event loop
root.mainloop()

And on Linux, we can use termios, but don't know if is it also available on Solaris.

import termios, sys, os                                                         
#import termios, TERMIOS, sys, os                                               
TERMIOS = termios                                                               
def getkey():                                                                   
        fd = sys.stdin.fileno()                                                 
        old = termios.tcgetattr(fd)                                             
        new = termios.tcgetattr(fd)                                             
        new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO                       
        new[6][TERMIOS.VMIN] = 1                                                
        new[6][TERMIOS.VTIME] = 0                                               
        termios.tcsetattr(fd, TERMIOS.TCSANOW, new)                             
        c = None                                                                
        try:                                                                    
                c = os.read(fd, 1)                                              
        finally:                                                                
                termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)                   
        return c                                                                
                                                                                
if __name__ == '__main__':                                                      
    print "type something...'q' to quit"                                        
    s = ''
    while 1:                                                                    
        c = getkey()                                                            
        if c == 'q':                                                            
                break                                                           
        print "captured key", c, ord(c)                                         
        s = s + c                                                               
                                                                                
    print "Password =", s
woooee 814 Nearly a Posting Maven

Take as look at list methods here. You can use insert

list_start=[[1,2], [2,2], [1,3]]
list_start.insert(1, [2,3])
print list.start
woooee 814 Nearly a Posting Maven

o, I have new_list = [52, 56, 57, 72, 85, 94]. I need to get difference between numbers from the list and average [52-51=1, ..., 72-51=21 and so on..], then raise the square of each, sum all them and divide from list length

Process each number and use a list if you want to store more than one number.

for num in new_list:
    total += num
    square_num =
    square_total += square_num
    average_dif = average_num - num:
etc
woooee 814 Nearly a Posting Maven
MsgDataType = c_uint8 * 8
 
msg = MsgDataType()

Not that you are using the same name twice.

print type(msg)
it may be a class in which case you would access it with
msg.field_name

woooee 814 Nearly a Posting Maven
key = key1 * (len(message)//(len(key1) + 1))

key1 is never defined anywhere. I think you meant something like:

key = key * (len(message)//(len(key) + 1))

although it's impossible to tell what you want from "it doesn't work". Note that the code as posted will yield a zero since "key" is longer than "message". Also, check the arithmetic

len(message)//(len(key1) + 1))
key1 -->
len(message
//
len(key)+1

In the future, include the error message as you won't get any responses to "it doesn't work".

woooee 814 Nearly a Posting Maven

Line 27, string is never defined, and you should not use "string" as a variable. That name is already used by Python.

message_text = "Message Box"
    message.setText(message_text)

At line 46, etc. use a variable to store the changes.

message = "attackatdawn"
    cap_str = message.upper()
    print message, message.upper()

Line 49: Trying to make the keyword repeat to make it at least as long as the message to encode (but this was a failure as well)

No idea what "this was a failure as well" means.

Line 57: Why does this not undraw the rectangle?

No idea what the graphics module uses (no one really uses graphics), but generally you have to use a variable to point to the object's location in memory, and then tell the program which object/memory location to undraw.

withdraw_rec = Rectangle(Point(80,155), Point(158, 110)).draw(win)
    dont_withdraw_rec = Rectangle(Point(180,55), Point(258, 10)).draw(win)
    withdraw_rec.undraw()
woooee 814 Nearly a Posting Maven

I would suggest using a single list with a sub-list containing [item, quantity, price]. Online explanations for lists and enumerate. Your original code slightly modified is below. Note that process_order_quantity will have to be changed to receive a single quantity and item, (which assumes that the discount is for single items > 10). You might want to return the discount and add it to the sublist as well. So as to not form bad habits, read the Python Style Guide when you have time (function names are all lower case with underscores, "_")

#get user input
items_list = []
subtotal = 0.0
for i in range(0,2,1):
    item = str(raw_input('Enter an item: '))
    quantity = int(raw_input('How many of these do you want? '))
    price = float(raw_input('Enter the price: '))
    items_list.append([item, quantity, price])   ## <----- appends a list

    ## add the subtotal
    this_subtotal = process_order_item(quantity,price)
    subtotal += this_subtotal
    print "subtotal is now", subtotal, "\n"

#loop over the lists -------------------------------------------------
#
# print each sublist
for sublist in items_list:
    print sublist

# print item, quantity, price
for this_sublist in items_list:
    print "item =", this_sublist[0], ",  quantity =", this_sublist[1], \
          ",  price =", this_sublist[2]
woooee 814 Nearly a Posting Maven

Check your post after posting. If it doesn't look right, hit the edit button and try again.

Beat you TONYJV by that much.

This is my first function in python and i need to get item quantity and price loops into the function Processorderitems. I took out the items loop because I was not doing anything with it. I need to return the subtotal and I have a 3% discount for quantities over 10. I am not sure how to loop the information into and out of the function. Do I send the list or can you send each index? I have tried both ways so far and get errors. Here is what I have now.

print "This program calculates a total after the user enters: \n the Item, Quantity and Price"
#define process function
def Processorderitem(quantitylist,pricelist):
    #discount variable so it can be changed
    discount = .03
    subtotal = 0
    for i in range(len(quantitylist)):
        for j in range(len(pricelist)):
            subtotal[i] = quantitylist[i] * pricelist[j]
    while quantity >= 10:
        subtotal *= discount
        subtotal -= discount
    return subtotal

#create lists for data
itemlist = []
quantitylist = []
pricelist = []
totlist = []
quantity = 0
price = 0
total = 0
discount = .03

#get user input
for i in range(0,2,1):
    item = str(raw_input('Enter an item: '))
    quantity = int(raw_input('How many of these do you want? '))
    price = int(raw_input('Enter the price: '))
    itemlist.append(item)
    quantitylist.append(quantity)
    pricelist.append(price)
    print itemlist,quantity,price
    
#loop over the lists
#    for item in enumerate(itemlist):
for …
woooee 814 Nearly a Posting Maven

The user enters a number and the program should output that amount of rows and colunmns.

Your for() loop actually prints the same number of __rows__ as the number entered by the user. Instead, you want to use a counter to count each object when it is printed/displayed. According to your diagram, you want to print up to number/2 and then print the bottom half=number/2 as well. Also, how would you print if an odd number, like 9, was entered. Here's an example for the top half to get you started:

number = 12
ctr = 0
row = 1

while ctr < number/2:
    print "*" * row, 
    ctr += row     ## number of objects printed
    print "    row =", row, "ctr is now", ctr
    row += 1
woooee 814 Nearly a Posting Maven

The encoding info is contained at the beginning of the file (I think), so that would write some sort of header to indicate the file's encoding, i.e. how to process the bytes following. The rest of the file would be just bytes, as all files are.

woooee 814 Nearly a Posting Maven

You would do something along the lines of the following. Note that if you open the file using a program that does not encompass encoding, then you will see what appears to be some garbage letters. This in not the file's fault, but the lies with the program being used to view it. Also, Python3.X has unicode built in, so what happens depends on which version of Python you are using. If there are any further questions, include the version of Python that you are using with the question.

fp = codecs.open('test', encoding='utf-8', mode='w+')
fp.write(u'\u4500 blah blah blah\n')

See this page http://docs.python.org/howto/unicode.html

woooee 814 Nearly a Posting Maven

bonuslist will always be the same as the saleval list
bonuslist = saleval
You add the bonus to the field named "bonus" but try to print "bonuslist" which you do not change. See if using a lists of lists, that is one sub_list for each [staff, sales, bonus] helps. Generally you would use a dictionary for each sales person pointing to a list containing sales & bonus, but I am assuming that you have not covered dictionaries yet. Also, do not use "i", "l", "or "O" as single digit variable names as they look too much like numbers.

sales_list = []
for i in range(0,3,1):
    staff = str(raw_input('Enter staff member Name: '))
    sales = int(raw_input('How much is the sale? '))
    if sales >= 0:
        bonus = 0
        ## if sales < > statements here
        sales_list.append ([staff, sales, bonus])

    ## --- this "i" is different from the "i" used in the for loop and does nothing
    ## i += 1

##--- print each sub-list
for ctr, this_entry in enumerate(sales_list):
    print ctr, this_entry

## print the second sales person
this_entry = sales_list[1]
print "\nname =" this_entry[0]
print "sales =", this_entry[1]
print "bonus =", this_entry[2]
woooee 814 Nearly a Posting Maven

Cleaned up the code for my own satisfaction so that all dictionary entries are of the same format, i.e. a list as the second element that can contain zero or more indexes to the game_dict.

regen() is defined on line 597, wearregen() on line 601. Both are used above that so should yield some kind of undefined error message.

game_dict = {}
game_dict['area'] = 0
game_dict['sword'] = 0
game_dict['pots'] = 20
game_dict['first'] = 'Harry'
game_dict['last'] = 'Palms'
 
text_dict = {}
text_dict[0] = ["Welcome ", ['first','last'], "to the world of slime fighter."]
text_dict[1] = ["You have ", ["pots"] ,"potions."]
text_dict[3] = ["Rested", []]
text_dict[4] = ["At least you're not naked", []]  ## spelling corrected
 
def textbox_conf(text):
    print "\ntext is always set to -1 and fg is always 'black'"
    list_to_print = text_dict[text] 
    text_string = list_to_print[0]
    for index in list_to_print[1]:     ## members of game_dict to print
       text_string += str(game_dict[index]) + " "
    for x in range(2, len(list_to_print)):
        text_string += list_to_print[x]
    print "textbox.configure test =", text_string
 
text = 1
textbox_conf(text)
 
text = 3
textbox_conf(text)
 
text = 1
game_dict['pots'] = 30
textbox_conf(text)

text = 0
textbox_conf(text)
woooee 814 Nearly a Posting Maven

I don't see "equip" declared anywhere so there is no way to tell what equip.delete() is trying to do, but there is too much code=too much wasted time, to sort through. Also, a dictionary container is your friend here. Pretty much all of the if statements can be replaced with a dictionary, and all of the variables at the beginning should be a dictionary or list so you only pass around one container. A simple example for setting the textbox using one function and a dictionary that is much more readable IMHO. The same can be done for armor, sword, etc.

game_dict = {}
game_dict['area'] = 0
game_dict['sword'] = 0
game_dict['pots'] = 20

text_dict = {}
text_dict[1] = ["You have", "pots" ,"potions."]
text_dict[3] = ["Rested"]
text_dict[4] = ["At least you're not naked"]  ## spelling corrected

def textbox_conf(text):
    print "\ntext is always set to -1 and fg is always 'black'"
    list_to_print = text_dict[text] 
    print "textbox.configure test =", list_to_print[0],
    next_el = 1
    if len(list_to_print) > 2:    ## we have a member of game_dict to print
        game_dict_index = list_to_print[1]
        print game_dict[game_dict_index],
        next_el = 2
    for x in range(next_el, len(list_to_print)):
        print list_to_print[x],
    print

text = 1
textbox_conf(text)

text = 3
textbox_conf(text)

text = 1
game_dict['pots'] = 30
textbox_conf(text)
woooee 814 Nearly a Posting Maven

Usually you should also strip the record first, as no data should be assumed to be 100% reliable. You may or may not want to convert to lower case as well.

for line in open('testconn.txt'):
    rec = line.strip()
    if rec.startswith('Domain') or rec.startswith('Referer'):
       print line
woooee 814 Nearly a Posting Maven

Add a print statement so you know what is being compared, and hence if the append is correct or not. Also, you should first check that both lists are the same length.

h=[]
for i in range(len(change2)):
	for j in range(len(atom)):
                print "comparing" atom[j], atom[i]
		if atom[j]==atom[i]:
			h.append("H")
		else:
			h.append("-")
print h
woooee 814 Nearly a Posting Maven

I have 2.7 installed on my Slackware disto. Bleachbit will not run with 2.7, so it may be that there are third party packages that have to be converted first.

woooee 814 Nearly a Posting Maven

How to add an entry to the file /etc/apt/sources.list

sources.list is a list of the repositories to search. It has nothing to do with the individual packages. Try 'man dpkg' and you should find something similar to (I don't remember the exact syntax for dpkg)
dpkg -f package_name
which you can use to see if Python2.6 is in one of the repositories. I found python2.6_2.6.6-6_i386.deb here so you should be able to install it normally. You can always Google for "deb package_name" as well to find something.

woooee 814 Nearly a Posting Maven

Add some swear words. That will make it mean. Also, add some print statements so you can see what the program is doing. And if you can not complete the problem, try it another way. Perhaps computing the mean by adding each element of the list to a total field, via a for loop. Obviously you do not understand what this code is doing so staring at it will not help; a different method may.

def mean(alist):
    belowMean = alist
 
    mean = sum(alist) / len(alist)
    print "I am mean, GRRRRR", mean
    print "comparing for <=", mean, "with", alist
    if mean <= alist:
        belowMean = item
 
    return belowMean
woooee 814 Nearly a Posting Maven

For unique descriptions, you would want to test the list also, only appending if that color is not already in the list, or use a set. Also, strip() both the description and the word before adding to the dictionary to get rid of spaces and newlines. Then you would use the length of the list/set.

woooee 814 Nearly a Posting Maven

You are mixing strings and lists. This should help.

class Sentence:
 
    def __init__(self, astr="I'm going back"):
        self.astr = astr
 
    def setWord(self, astr):
        self.astr=astr
 
    def getfirstword(self):
        return ' Changer the word back', self.astr[2]

    def getallword(self):
        print "astr[2]", self.astr[2]
        astr_list = self.astr.split()
        print "astr_list[2]", astr_list[2]
        astr_list[2] = "XXX"
        print "join", " ".join(astr_list)
##        self.astr[2] = "home"
        return self.astr
 
sent = Sentence()
 
print sent.getfirstword()
ret_val = sent.getallword()
print type(ret_val), ret_val
Ghostenshell commented: Thanks again. +2
woooee 814 Nearly a Posting Maven

A good example of using a class is in this tutorial. Note especially the use of "self" and the indentation.

woooee 814 Nearly a Posting Maven

Pass the "driver" to a class function which appends to the list. The same for deleting from the list. You should try to keep all methods within the class.

woooee 814 Nearly a Posting Maven

Take a look at this tutorial, especially the references to "self".

woooee 814 Nearly a Posting Maven

squares() never saves or prints the perfect squares within the while loop, (or tests if the arg "num" is ever found as a perfect square if that is what you want to do. I can't tell as there are no comments in the code). Add a print statement which will tell you that the problem is with incrementing.

def squares(num):
    i = 1
    s = 0
    while s <= num :
        s = (i * i)
        print "testing", i, s, "compared to", num
        i = i + 1
    return s
##
## also, you have redundant code, i.e calling squares several times
    while num <= stop:
        ret_s = squares(num)
        if num == ret_s:
            print ret_s
##  the else statement does nothing
##        else :
##            num = num
        num = num + 1
woooee 814 Nearly a Posting Maven

You would have to return big_num. This is a modified version of the first problem, using a string to store the output. It shows passing variables. Try it and add some print statements so you know what is happening. Post back with any problems.

def main():
 
    x = input("Enter an integer (the number of times to print): ")
    y = input("Enter another integer (the number to be printed): ") 
 
    message(x,y)
    print     ## goto a new line
    ret_str = using_a_string(x, y, "")
    print ret_str[:-2]     ## strip last " +"
 
def message(x,y):
 
    if (x > 0):
        print y, "+", 
        message(x - 1,y)

def using_a_string(x, y, str_out):
    if (x > 0):
        str_out += " %d +" % (y) 
        str_out = using_a_string(x - 1, y, str_out)
    return str_out
main()
woooee 814 Nearly a Posting Maven

Sorry, I missed the recursion part. You want to print "y", since you are using "x" as the number of times to print, and you only print "y" once per function call. Since the function calls itself until x = 0, each call in turn will print one "y" value. There is a trailing "+" on the end when using this code. You will have to test for x==1 to get rid of it. FYI, recursion is rarely used in the real world, and is considered bad coding style by some, so you probably won't have to use this outside of the class.

def main():
    x = input("Enter an integer (the number of times to print): ")
    y = input("Enter another integer (the number to be printed): ")
 
    message(x,y)
    print     ## goto a new line

  
def message(x,y):
    if (x > 0):
        print y, "+", 
        message(x - 1,y)


main()
woooee 814 Nearly a Posting Maven
1   2   3   4   5   6   7??
The book has an example of 7 * 4 = 4 + 4 + 4 + 4 + 4 + 4.

I hope that's a typo on your part, otherwise you should find another book. Sorry, couldn't pass that one up. You want to start thinking of data as bytes that you use or format however you want. So, the following are 2 more ways. I'm sure there are others.

multiplier = 7
output_str = "4"
for ctr in range(multiplier-1):
    output_str += "+4"
print output_str
#
output_list = []
for ctr in range(multiplier):
   output_list.append("4")
print "+".join(output_list)
woooee 814 Nearly a Posting Maven

I would suggest a dictionary with the key pointing to a list, which would show up similar to your example

D_dict = {"D1":[0, 0, 1, 0, 0, 1, 0, 0, 0 ],
          "D2":[0, 1, 0, 0, 0, 1, 1, 1, 0 ] }

Come up with some code to read the file and split/compare the words, and post back with any problems.

woooee 814 Nearly a Posting Maven

I know this is newbie basics - sorry about that

As long as you learned something and are making progress. Please mark the thread "Solved". Also, I would place the statement
a,b = max(a,b),min(a,b) #making sure a>b
under the function so you can send any two values to it and have the function take care of the max/min part. And do you want to test for two numbers that are the same, again the function should do this for you.

Seems to run ok.

Capture the value "a" returned by the function.
ret_a = fac(a,b) #running the function on a and b
print "final 'a' value is", ret_a

woooee 814 Nearly a Posting Maven

It doesn't have to be raw_input, as long as it's a prompting function that can be connected to a variable.

I don't want images. And I want to be able to prompt.

Make up your mind. Those of us who volunteer have a limited amount of time to spend here and do not wish to waste it generating code that will not be used.

woooee 814 Nearly a Posting Maven

Some comments

initialize a dictionary: dictionary 1
dd = {}

"""  indentation is wrong
"""
    dd.setdefault(column3, 0)
    # increment dd[port number] by one
    dd[column3] += 1

"""  get_port_name() does not return anything so the
     dictionary, ports_name, is empty
     Take a look at "1.1. A first program" 
     cut and paste this link
     http://www.pasteur.fr/formation/infobio/python/ch01.html#d0e115
"""
ports_name={} # dictionary 2
get_port_name ('Ports', ports_name)
 
# if the key in dd equals the key (item) in ports_name, insert the value of that item to the third column in the output file:
for key in dd.keys():
    if key in ports_name:
        print ports_name[key]     ## description

##    for item in ports_name.keys():
##        if key == item:
	    #I want the description to be retrievable by the key in dd and then have the description of the numbers on the third column of the output file and that 
##            dd[key][1]= ports_name[item]            
 
f.close()
outfile.write("\n".join(["%s %s %s" % (key, dd[key][0], dd[key][1]) for key in dd]))
outfile.close()
woooee 814 Nearly a Posting Maven

A simple example using Tkinter's after feature. You would probably want after to call a clean-up function to check for partial entries, etc., and then call quit().

import Tkinter

class TestClass():

   def __init__(self):
      
      self.top = Tkinter.Tk()
      self.top.title("Test of Timing")
      self.top.geometry("200x150+10+10")

      label_1 = Tkinter.Label(self.top, text="Timer Test ").pack(side="left" )
      entry_1 = Tkinter.Entry(self.top, width=10).pack(side="left")

      self.top.after(5000, self.top.quit)     ## 5 seconds
      self.top.mainloop()
         
if __name__ == '__main__':
   CT=TestClass()
woooee 814 Nearly a Posting Maven

Unless I am missing something, look up the key from the first dictionary in the second dictionary.

woooee 814 Nearly a Posting Maven

Same old, same old = add some print statements to tell you what is going on.

def fac(a,b): #defining the function that uses Euclid's method
    ctr = 0
    while b>0:
        ctr += 1
        a, b = b, a%b # changing the numbers a to b, and b to remainder of a/b
        print "a & b are now", a, b, ctr
        return a