woooee 814 Nearly a Posting Maven

And please do a reasonable number of tests of your code before posting. This is a truncated version of the function to point out the error:

def isprime(n):
    for ctr in range(2,n):  ## do not use 'i', 'l', 'O' as they can look like numbers
        if n%ctr==0:
            return 'Not a prime number',ctr,'is a factor'
        else:
            return 'Prime number'

print isprime(9)  ## 9 is not prime-->3**2
woooee 814 Nearly a Posting Maven

This code can be simplified.

if 2 <= c_no <= 10:
    gpa(c_no)
#
## replaces, (and note that the "pass" does nothing)
if c_no==2: #if the no of courses inputed is 2
    gpa(2)
elif c_no==3: #if the no of courses inputed is 3
    gpa(3)
elif c_no==4: #if the no of courses inputed is 4
    gpa(4)
elif c_no==5: #if the no of courses inputed is 5
    gpa(5)
elif c_no==6: #if the no of courses inputed is 6
    gpa(6)
elif c_no==7: #if the no of courses inputed is 7
    gpa(7)
elif c_no==8: #if the no of courses inputed is 8
    gpa(8)
elif c_no==9: #if the no of courses inputed is 9
    gpa(9)
elif c_no==10: #if the no of courses inputed is 10
    gpa(10)
else:
    pass

Also, you can use a dictionary to shorten the first block of code if you are familiar with dictionaries. And if you want input until a correct number is entered and also not error out when an alpha is entered:

c_no = 0
while c_no not in range(2, 11):
    c_no=input('Number of courses offered')

    try:
        c_no = int(c_no)        ## allows for any alpha characters
    except:
        c_no = 0

gpa(c_no)
e-papa commented: Cool comment, hope to help others like you someday +1
woooee 814 Nearly a Posting Maven

What does the function normDistProb return? The first attempt to debug this should be to print it

for i in range(0,12):
    listProbFog.append(normDistProb(dayValues[i], fogAve[i], fogVar[i]))
    print normDistProb(dayValues[i], fogAve[i], fogVar[i])
    print listProbFog
    # the other lists are just extra cruft until you get this problem solved
bumsfeld commented: agree +7
woooee 814 Nearly a Posting Maven

Also, form the habit of using a list instead of if/elif. It is more straightforward as all of the conditions are on one line. And verb[-2:] is just shorthand for verb[-2:len(verb)], just as verb[:-2] is shorthand for verb[0:-2].

verb = input("Write the verb here: ")
if verb[-2:] in ['ar', 'er', 'ir']:
#
else:
#
# or
found = False
for ending in ['ar', 'er', 'ir']:
    if verb.endswith(ending):
        found = True
Gribouillis commented: good pattern +6
woooee 814 Nearly a Posting Maven

A second dictionary is not required. Create a tuple containing item1 and item2 and look up in the dictionary. If found, you have a match. If you want to keep the keys in the same order as the file, use the ordered dictionary. For Python 2.7 it is in "collections".

woooee 814 Nearly a Posting Maven

Code tags added.

I want to create a function wich prints all numbers over 1000000.
So the user can input for example 500 and that dosent print but if you input 1005000 it prints.

My code far is.

v = [600,6300330,47, 1000001]

for x in v
	if x >1000000:
		print x
woooee 814 Nearly a Posting Maven

You can't combine grid() and pack() but must use one or the other. Also, AFAIK, one radio button must be selected (a default selection or you can't choose 'none' when using radio buttons), and the others can be deselected.

from Tkinter import *
 
class App:
   def __init__(self, parent):
    self.my_parent = parent
    self.my_parent.geometry("200x100+10+10")
#    self.fm = Frame(parent, width=400, height=300)
#    self.fm.pack_propagate(0) # to keep the frame size
#    self.fm.pack()
 
 
    self.R1 = Radiobutton(self.my_parent, text="Red", value=1, command=self.make_Red)
    self.R1.grid(row =2 , column = 1)
    self.R1.select()

    self.R2 = Radiobutton(self.my_parent, text="Blue",  value=2, command=self.make_Blue)
    self.R2.grid(row =2 , column = 2)
    self.R2.deselect()
 
    self.R3 = Radiobutton(self.my_parent, text="Green", value=3, command=self.make_Green)
    self.R3.deselect()
    self.R3.grid(row =2 , column = 3)
 
 
   def change_buttons(self, color):
       self.my_parent.configure(bg=color)
       self.R1.configure(bg=color)
       self.R2.configure(bg=color)
       self.R3.configure(bg=color)

   def make_Red(self):
       self.change_buttons("Red")
 
   def make_Blue(self):
       self.change_buttons("BLUE")
 
   def make_Green(self):
       self.change_buttons("GREEN")
 
root = Tk()
root.title ("Color Option")
app = App(root)
root.mainloop()
Gribouillis commented: Tkinter Guru Award. +5
woooee 814 Nearly a Posting Maven

Use a for() loop with step=3.

DNA= "ATCGATCGATCGATC"
for ctr in range(0, len(DNA), 3):
    print DNA[ctr:ctr+3]
woooee 814 Nearly a Posting Maven

Doug Hellmann's write-up.

woooee 814 Nearly a Posting Maven

The difference between
name1,number1;name2,number2;name3,number3
and
name1,number1
name2,number2
name3,number3
is a newline. Use rstrip() to strip the newline before you write to the output file.
out.write(line.rstrip())

woooee 814 Nearly a Posting Maven

I'm not sure I understand your question but if you want to use multiple class instances, one per dog, try something like this.

if __name__ == "__main__":
	dogs = list()
        dog_name = ""
	first_inp = "Name: ('quit' to exit) "
	second_inp = "Breed: "
	while dog_name.lower() != "quit":
		dog_name = input(first_inp).strip()
		dog_breed = input(second_inp).strip()
		this_instance = Dog(dog_name, dog_breed)
                dogs.append(this_instance)
        for each_instance in dogs:
            print(each_instance.name, each_instance.breed)
woooee 814 Nearly a Posting Maven

Run the input files one at a time, i.e. run the program using the first file and check the output, then run the program again using the second file and check the output file, etc.

woooee 814 Nearly a Posting Maven

To be complete, Linux requires style=wx.TE_PROCESS_ENTER

import wx
 
class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, -1, mytitle, size=mysize)
        self.SetBackgroundColour("white")
        s = "Enter the price:"
        label = wx.StaticText(self, -1, s, pos=(10,10),)
        self.edit = wx.TextCtrl(self, -1, pos=(10, 30), \
                                size=(100, 25), style=wx.TE_PROCESS_ENTER)
        # respond to enter key when focus is on edit
        self.edit.Bind(wx.EVT_TEXT_ENTER, self.onAction)
        self.edit.SetFocus()
         
    def onAction(self, event):
        """
        check for numeric entry and limit to 2 decimals
        accepted result is in self.value
        """
        raw_value = self.edit.GetValue().strip()
        print raw_value
        # numeric check
        if all(x in '0123456789.+-' for x in raw_value):
            # convert to float and limit to 2 decimals
            self.value = round(float(raw_value), 2)
            self.edit.ChangeValue("%9.2f" % (self.value))
        else:
            self.edit.ChangeValue("Number only")
 
 
app = wx.App(0)
# create a MyFrame instance and show the frame
mytitle = 'Numeric entry test'
width = 450
height = 200
MyFrame(None, mytitle, (width, height)).Show()
app.MainLoop()
woooee 814 Nearly a Posting Maven

"row" is a string, and strings are immutable, i.e. can not be changed, so you have to catch the return and use it.

for row in open('C:\\test.xml','r'):
    if 'RecCount' in row:
        print row
        new_row = row.replace('RecCount','12345')
        print new_row
woooee 814 Nearly a Posting Maven

Test the code you have before posting it here. For example, in the Deck class, there is an indentation error, and the variable "c" [c = Card(rank, suit)] is an instance of the class Card. To access the rank and suit from the Deck class, you would use
self._cards[ctr].rank and self._cards[ctr].suit
where ctr = a number between 0 through 51. Is this what you want? Also,
if len(self) == 0:
should error because "self" is a pointer to this class and has no length.

To answer your question directly, if all cards are the same suit as the first card, it is a flush. If the hand is sorted in numerical order and each card = previous card +1 then you have a straight. For now though, get the code you have working (print the deck after it is created and the hands after they are dealt at the very least). Note that you can also use a dictionary for changing the numbers to J, Q, K, or A. Also, you would possibly use a dictionary to store the relative value of the different hands so you know which hand wins.

rank_dict = {11: 'J',
             12: 'Q',
             13: 'K',
             14: 'A' }

## test dictionary use
rank = [2, 12]
for r in rank:
    print r,
    if r in rank_dict:
        print rank_dict[r]
    else:
        print r
"""
    The dictionary replaces the following code

    if self.rank == 11:
      rank = 'J'
    elif self.rank == 12:
      rank …
woooee 814 Nearly a Posting Maven

Print projData, and type(projData) to see what it is. Read "Basics"in this page especially the use of a for() statement, for some help with using lists. Python naming conventions/style guide.

woooee 814 Nearly a Posting Maven

Take a look at the "Starting Python" sticky at the top of this forum. There are many resources, including the Google (free) online course.

vegaseat commented: worth it +13
woooee 814 Nearly a Posting Maven

Also, calculate (p0 * math.e) once before the for() instead of every pass calculating it again. You should be using one for() loop, since they all do the same thing.

numeratorPos1 = 0
numeratorPos2 = 0
denominatorPos = 0
p0_math_e = p0 * math.e
for x in range(0, n):        
    y = p0_math_e**(-(decay * x))

    numeratorPos += ((x**2)*y)
    numeratorPos += (y*(math.log(y)))
    denominatorPos += y
#
# etc.
woooee 814 Nearly a Posting Maven

Usually that means that two items point to the same memory address, but without knowing more about "plant" (whether it is a string, list, etc.), and the same for Nplant (a list or list of lists?), there is no way to tell. Insert this code after appending, which prints the id, and see if 2 or more id's are the same.

for pl in Nplants:
    print id(pl)

For more help, post a complete code snippet, that will run as is, and some sample data to use for appending.

woooee 814 Nearly a Posting Maven

You are coding the button callback incorrectly. When you produce 102 lines of code with no testing, it is very difficult to find which line is segfaulting amongst all that code. Apparently no one else wanted to sift through all of this either. For starters, break this up using functions so you can test each function individually. The variables "RESOLUTION" and "CARRIERS" have not been declared in this class, so you will get an error. Note that the following program runs, but obviously still requires some work.

import wx

class EnterEmail(wx.Frame):
    def __init__(self, parent,id,title):
##        wx.Frame.__init__(self,parent,id,title,size=(RESOLUTION[0]/1.5,RESOLUTION[1]/1.5))
        wx.Frame.__init__(self,parent,id,title)
        self.parent=parent
        font5 = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL)
        font3 = wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL)
        font1 = wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD,True)
        self.SetBackgroundColour('#f2f200')
 
 
        sizer=wx.BoxSizer(wx.VERTICAL)
        panel0=wx.Panel(self,-1)

        infoLabel = wx.StaticText(panel0, -1, "Enter your phone and/or email information.")
        infoLabel.SetFont(font3)
 
        """
        panel1=wx.Panel(self,-1)
        hsizer=wx.BoxSizer(wx.HORIZONTAL)
        vsizer=wx.BoxSizer(wx.VERTICAL)
        vsizer2=wx.BoxSizer(wx.VERTICAL)
 
        emailLabel=wx.StaticText(self,-1,"Email")
        emailLabel.SetFont(font1)

        emailBoxLabel=wx.StaticText(self,-1,"Enter your e-mail address:")
        emailBoxLabel.SetFont(font5)

        self.email = wx.TextCtrl(self, -1, size=(300, 30))
        self.email.SetFont(font3)
 
        emailBoxLabel2=wx.StaticText(self,-1,"Confirm e-mail address:")
        emailBoxLabel2.SetFont(font5)
        self.confirmEmail = wx.TextCtrl(self, -1, size=(300, 30))
        self.confirmEmail.SetFont(font3)
 
        phoneLabel=wx.StaticText(self,-1,"Phone")
        phoneLabel.SetFont(font1)
 
        carrierLabel=wx.StaticText(self,-1,"Please select your service provider:")
        carrierLabel.SetFont(font5)
        self.carrierChoice=wx.Choice(self,-1,size=(300,30))
        self.carrierChoice.SetFont(font3)
        CARRIERS = ["abc", "def", "hij"]
        self.carrierChoice.AppendItems(strings=CARRIERS)
 
        numberLabel=wx.StaticText(self,-1,"Enter your phone number:")
        numberLabel.SetFont(font5)
        self.number= wx.TextCtrl(self, -1, size=(300, 30))
        self.number.SetFont(font3)
        """ 
        self.sendButton=wx.Button(panel0, -1,"Send", (30,30))
        self.sendButton.Bind(wx.EVT_BUTTON, self.OnSubmit)
        """ 
        self.startOverBut=wx.Button(self,-1,"Cancel",size=(150,30))
        self.Bind(wx.EVT_BUTTON,self.OnClose,self.startOverBut)
 
        #hooking it all together
        vsizer.Add(emailLabel,0,wx.TOP|wx.ALIGN_CENTER,5)
        vsizer.Add(emailBoxLabel,0,wx.TOP|wx.ALIGN_CENTER,25)
        vsizer.Add(self.email,0,wx.TOP|wx.ALIGN_CENTER,10)
        vsizer.Add(emailBoxLabel2,0,wx.TOP|wx.ALIGN_CENTER,25)
        vsizer.Add(self.confirmEmail,0,wx.TOP|wx.ALIGN_CENTER,10)
 
        vsizer2.Add(phoneLabel,0,wx.TOP|wx.ALIGN_CENTER,5)
        vsizer2.Add(carrierLabel,0,wx.TOP|wx.ALIGN_CENTER,25)
        vsizer2.Add(self.carrierChoice,0,wx.TOP|wx.ALIGN_CENTER,10)
        vsizer2.Add(numberLabel,0,wx.TOP|wx.ALIGN_CENTER,25)
        vsizer2.Add(self.number,0,wx.TOP|wx.ALIGN_CENTER,10)
 
        vsizer.Add(self.startOverBut,0,wx.TOP|wx.EXPAND,25)
        vsizer2.Add(self.sendButton,0,wx.TOP|wx.EXPAND,25)
 
        sizer.Add(infoLabel, 0, wx.TOP|wx.ALIGN_CENTER, 5)
        panel0.SetSizer(vsizer)
        panel1.SetSizer(vsizer2)
        hsizer.Add(vsizer,0,wx.LEFT|wx.ALIGN_LEFT,5)
        hsizer.Add(vsizer2,0,wx.LEFT|wx.ALIGN_RIGHT,5)
 
 
 
        sizer.Add(hsizer)
        self.SetSizer(sizer)
 
        self.Centre()
        self.Bind(wx.EVT_TIMER, self.OnUpdateTimer)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow())
        """

        self.Show(True)
        print 'done '

    def OnSubmit(self,event):
        print "OnSubmit called"

    def OnUpdateTimer(self,evt):
        pass

    def OnClose(self):
####        self.email.Destroy()
####        self.confirmEmail.Destroy()
####        self.carrierChoice.Destroy()
#### …
woooee 814 Nearly a Posting Maven

It possibly has something to do with the unconventional way you are including/calling Tkinter. The standard way is here. The following code works on my Slackware Linux system.

import Tkinter

class App():
    def __init__(self):
        self.parent = Tkinter.Tk()
        self.initialize() 
        self.parent.mainloop()
 
    def initialize(self):
        self.itemVar = "abc"
        for r in range(8):
            mode = r*2+1
            self.itemOdds =  Tkinter.Radiobutton(self.parent, text="item"+str(mode),
                        variable=self.itemVar, value=mode)
            self.itemOdds.grid(row=r, column=0)
 
        EVENS = [
            ('item0', 0),
            ('item2', 2),
            ('item4', 4),
            ('item6', 6),
            ('item8', 8),
            ('item10', 10),
            ('item12', 12),
            ('item14', 14),
        ]
 
        r = 0
        for text, mode in EVENS:
            self.itemEvens = Tkinter.Radiobutton(self.parent, text=text,
                        variable=self.itemVar, value=mode)
            self.itemEvens.grid(row =r, column=1)
            r += 1

if __name__ == "__main__":
    app = App()
woooee 814 Nearly a Posting Maven

Also you are using "is" instead of equal. "is" tests for the same object, so can not be relied upon for an equal condition. Finally, the statement

else:
    if p is primes[len(primes)]:

is unnecessary. The for loop takes care of that. So, you could use an indicator like this instead.

prime_found = True
        for p in primes:
            if test_int % p is 0:
                prime_found = False
                break
        if prime_found:
            primes.append(test_int)
##
##-------------------------------------------------------------------
##   a short example of "is" vs. "=="
x = "abc"
y = "abcd"
print x is y, id(x), id(y)        ## prints False
print x is y[:3], id(x), id(y)    ## prints False
print x == y[:3], x, y[:3]        ## prints True
woooee 814 Nearly a Posting Maven

First, do not read the entire file at one time, i.e. readlines(), instead:

for rec in open(file_name, "r"):
    if key in mydictionary: 
        mydict[key]+=1 
    else: 
        mydictionary[key] = 1

If that doesn't help then you will have to switch an SQL file on disk. SQLite is simple to use for something like this so post back if you want some help.

woooee 814 Nearly a Posting Maven

Generally speaking you open a new frame, not a new mainframe. There is no way to tell how the class is called from the sample, but you would access variables the same way as with any other class.

##--- Not tested
class Window_Test():
     def __init__(self):
          x=10
          ## instance of the class
          fr = Frame_Test()
          ## call the function
          y = fr.fn(x)
          print "y =", y
          print fr.var
          return x

class Frame_Test():
     def __init__(self):
         self.var = "class Frame_Test variable"

     def fn(self, x):
         print "fn called -->", x
         return x + 1

W=Window_Test()
woooee 814 Nearly a Posting Maven

It appears that the OP wants to open a web browser, i.e. subprocess.call("firefox"), and then submit some data after some period of time from a running program, which is beyond my knowledge. AFAIK you either do everything in the program or everything in the browser, especially if the page is changing.

vegaseat commented: good point +13
woooee 814 Nearly a Posting Maven

In:
07:34 08:55 10 20
08:25 09:00 10 20
Out:
08:25 09:00 10 20
07:34 08:55 10 20

For a reverse order sort like this, you simply compare for greater instead of lesser, which Python sorts will do with the reverse=True parameter set. Do you also want to take into account the "10 20" which I assume is a date?

woooee 814 Nearly a Posting Maven

There are two problems that I can see. It should be "root.mainloop" and there is no config statement for load menu so only the empty "menubar" is displayed. Also, note the inconsistent use of master and self.master. I did not test with any of the commented lines included. If they contain other problems that you can not solve, post back.

from Tkinter import *
 
class Application(Frame):
 
    def __init__(self, master=None):
#        Frame.__init__(self, master)
#        self.master.rowconfigure(0, weight=1)
#        self.master.columnconfigure(0, weight=1)
#        self.master.title('Test Menu')
        self.createMenu(master)
        #self.createShell()
 
    def createMenu(self, master):
#        menubar = Menu(master)
 
        loadmenu = Menu(master)
        loadmenu.add_command(label='Load', command=self.load)
        loadmenu.add_command(label='Save', command=self.save)
        loadmenu.add_separator()
        loadmenu.add_command(label='Quit', command=master.quit)
        #master.grid()
        master.config(menu=loadmenu)
 
    def createShell(self):
        frame = Frame(width=400, height=300)
        frame.grid() 
 
    def load(self):
        print "load called"
 
    def save(self):
        print "save called"
 
    ## this function is not being used by the code as it is now
    def quit(self):
        pass
 
 
root = Tk()
app = Application(master=root)
root.mainloop()
woooee 814 Nearly a Posting Maven

The middle rectangle, be it red or white is centered, so if you have a 200x200 canvas, the middle would be 100. You can then move left or right, calculating the end position of the first red square for the rows with 4 red squares; end position=middle - (1.5 white + 1 red). The other row is obviously rectangles of the same size.

woooee 814 Nearly a Posting Maven

I don't have a lot of time, but here is a simple example to start you, using Tkinter. The other GUI toolkits, WxPython and QT, would be similar.

from Tkinter import *

root = Tk()
root.title('Rectangle Test')
canvas = Canvas(root, width =300, height=300)

## top_left_x, top_left_y, bottom_right_x, bottom_right_y
points_list = [0, 0, 25, 25]
color = "red"

for row in range(3):
    for col in range(3):
        rectang = canvas.create_rectangle(points_list[0], points_list[1], \
                              points_list[2], points_list[3], fill=color)
        ## increase along the x axis
        for point in [0, 2]:
            points_list[point] += 50

    ## move down one row
    if row%2:      ## row is an odd number
        points_list = [ 0, points_list[1]+25, 25, points_list[3]+25]
    else:          ## row is an even number
        points_list = [25, points_list[1]+25, 50, points_list[3]+25]

canvas.pack()
root.mainloop()
woooee 814 Nearly a Posting Maven

You search a dictionary in this way, and note that names would be case sensitive:

def search(dict1):
    name2=raw_input("Enter the name whose number is to be found: ")
    if name2 in dict1:
        print name2, dict1[name]
woooee 814 Nearly a Posting Maven

Hey, I've got an array full of random numbers

It depends on how many levels are in the array. Generally, you would flatten the array into a single level list, and operate on that. If you want to keep the original structure, then you have to test for the type. If it is an integer you can modify if. If it is a list, then you have to traverse the inner list. Recursion would probably be the best choice for doing that.

woooee 814 Nearly a Posting Maven

If you are using Python3.X, then input will return a string which is always greater than 100, print type(score) to see which class it belongs to.

woooee 814 Nearly a Posting Maven

Note also that you start with zero, not one, and your zero replaces 21, and your 21 replaces 16. One problem is that you generate 26 numbers, zero through 25, with only 25 spaces to hold them. I have no other advice because "And here is what the square is supposed to print" yields this solution:
print "11 18 25 2 9"
etc. as there is nothing else that can be deduced from the question.

woooee 814 Nearly a Posting Maven

It depends somewhat on what widget you want to set, but generally you can use configure. This is something I have lying around from somewhere and added a configure to change the background and foreground of the button when the top button is pressed. Another example is here. You also want to become familiar with the class structure as it is much easier to pass variables around when coding a GUI. The example at the link posted shows how to use a class for this.

from Tkinter import *

def callback1() :
    print "Callback #1"
    option1.configure(bg = 'white', fg='green')

def callback2() :
    print "Callback #2"

def callback3() :
    print "Callback #3"

##===============================================================
top = Tk()

##---  always place in upper left corner ( +10+10 )
##     size = 200x200 = minimum size so it's big enough to be seen
top.geometry("150x150+10+10" )

label1 = Label( top, text = "Test Menu" )
label1.pack()

label2 = Label( top, text = "" )          ## blank line = spacer
label2.pack()

option1 = Button(top, text='Option 1',
       command=callback1, bg='blue', fg='white' )
option1.pack(fill=X, expand=1)

option2 = Button(top, text='Option 2',
       command=callback2, bg='green', fg='white' )
option2.pack(fill=X, expand=1)

option3 = Button(top, text='Option 3 - No Exit',
       command=callback3, bg='black', fg='white' )
option3.pack(fill=X, expand=1)

exit=  Button(top, text='EXIT',
       command=top.quit, bg='red', fg='white' )
exit.pack(fill=X, expand=1)

top.mainloop()
woooee 814 Nearly a Posting Maven

I'm sure I could but I'm not the one who's taking the class.

vegaseat commented: right on +13
woooee 814 Nearly a Posting Maven

Adding a print statement should help. If you want to store more than one value, a list is usually the container of choice.

def gp(a1,r,n):
    ## can also be done with list comprehension
    print [ a1 * (r ** x) for x in range(n)]

    while n > 0:
        n = n - 1   ## if 'n' was 1 it is now zero
        an = a1 * (r ** n)
        print n, "returning", an
        return an
woooee 814 Nearly a Posting Maven

Connect stderr to a pipe, and you also have to flush the pipes, see, "Doug Hellmann's Interacting with Another Command" which is what I think you want to do. Also take a look at pexpect which should suffice from what you have explained, and is simple to use.

woooee 814 Nearly a Posting Maven

The limits of floating point numbers
http://www.lahey.com/float.htm
http://docs.python.org/tutorial/floatingpoint.html
Use decimal for more precision.

from decimal import Decimal as dec

# 0.1 + 0.1 + 0.1 - 0.3 = 0.0
x = dec("0.1")
y = dec("0.3")
print x + x + x - y
woooee 814 Nearly a Posting Maven

Some print statements should help. Note that "word" will only contain the final word in a sentence. Once you can get each word, add a counter to count the letters as they are added to the new "word" field or what ever you wish to use.

m = input("Enter a string ")
i = 0
m=m+" "
while m[i]==" ": i=i+1
print("#1 i =", i)
print ()
print("while i<len(m)-1-->", i, "< ", len(m)-1)
while i<len(m)-1 :
    print "     i in while =", i
    word = ""
    while m[i]==" ": i=i+1
    while m[i] != " " :
        word = word + m[i]
        i=i+1
print("final print", word, "i =", i)
woooee 814 Nearly a Posting Maven

What happens if the first "Steve" is 7 instead of 1 -----> , , ], etc. Should it be at the end of the first list or at the end of all of the items? Generally, you would flatten the list and then sort if all items are to be sorted equally.

import itertools
import operator

r =[[['steve',7, 40], ['steve',3, 20], ['steve',2, 30]],
    [['john',5, 50], ['john',6, 40], ['john',4, 30]]]

r_flat = list(itertools.chain(*r))
r_flat.sort(key=operator.itemgetter(1))
print r_flat
#
#output =[['steve', 2, 30], ['steve', 3, 20], ['john', 4, 30], 
#         ['john', 5, 50], ['john', 6, 40], ['steve', 7, 40]]
vegaseat commented: fine observation +13
woooee 814 Nearly a Posting Maven

I must fix a code so I can write roman letters (bigger than 3999)

For Arabic, if it is larger than 3999 subtract 1000 and add 1000 to a separate field until it is less than 4000. You would then divide the "thousands" field by 1000, convert and print with parentheses, since 4000=(IV). Do the reverse for Roman, i.e. convert then parens to Arabic and multiply by 1000, then add to the rest of the number.

woooee 814 Nearly a Posting Maven

Search for something like geometry in Tkinter's winfo, which you would have to call at the time the first window closes. I've never done anything like this so am not sure if it will work or not, so post back with any success or failure for future question.

woooee 814 Nearly a Posting Maven

This is a tic-tac-toe program that I coded some time ago. I doubt you will be able to use much of it, but it illustrates how much simpler it is when you break everything up into small pieces.

import random

class TicTacToe:
   def __init__(self):
      ## 0=No winner,      1=Player #1 wins,
      ## 2=Player #2 wins, 3=Tie
      self.winner = 0

      self.board = [0, 0, 0, 0, 0, 0, 0, 0, 0,]
      self.num_moves = [0, 0, 0]
      self.player = 1
      self.win_combos = (set([0, 1, 2]),
                         set([3, 4, 5]),
                         set([6, 7, 8]),
                         set([0, 3, 6]),
                         set([1, 4, 7]),
                         set([2, 5, 8]),
                         set([0, 4, 8]),
                         set([2, 4, 6]) )
      self.play_a_game()

   ##-----------------------------------------------------------------
   def play_a_game(self):
      while not self.winner:
         self.num_moves[self.player] += 1
         ##  a list of all squares not occupied
         squares_to_choose = [ctr for ctr, square in enumerate(self.board) \
                              if square==0]
         print "Choose from", squares_to_choose
         ##  choose a random available square
         square = random.choice(squares_to_choose)
         print("---> player %d occupies %d" % (self.player, square))
         self.board[square] = self.player
         self.print_squares()

         winner = self.we_have_winner()
         if not winner:
             self.tie()
 
         self.player = [0, 2, 1][self.player]

   ##-----------------------------------------------------------------
   def print_squares(self):
      for row in range(0, len(self.board), 3):
         for col in range(3):
            print self.board[row+col],
         print

   ##-----------------------------------------------------------------
   def tie(self):
     if 0 not in self.board:
         self.winner = 3
         print("Tie, you kissed your sister")

   ##-----------------------------------------------------------------
   def we_have_winner(self):
       """ extract all of the squares occupied for this player into 
           a set and check if it has a winning combo as a subset
       """
       moves = set([ctr for ctr, person in enumerate(self.board) \
                    if person==self.player])
       for win_combo in self.win_combos:
          if win_combo.issubset(moves):
               self.winner = …
woooee 814 Nearly a Posting Maven

In addition to the iterating through lists link above, there is also list comprehension which is the simplest way to do this.

testing = ['This', 'is', 'a', 'string'
print [x for x in testing if "t" in x.lower()]
woooee 814 Nearly a Posting Maven

Code this one step at a time. So first, get the input and check that it is indeed 'r', 'p', or 's'. Then generate a random choice for the computer, etc. BTW you have a lot of redundant code in this function.

def play_RPS(x, num_games):
    print 'Press q at any time to quit'
    text=''
    while text!='q':
        text=raw_input("Please choose rock(r), paper(p), or scissors(s):")
        if text=='q':
            print "Thanks for playing!"
            break 

        if text not in ['r', 'p', 's']:
            print "incorrect letter entered"
        else:
            random_throw=random.choice(x)
            num_games += 1
            return random_throw, num_games

    return "*", num_games


##----- the rest of the code repeats the same thing
        elif text== 'r':
            random_throw=random.choice(x)
            print random_throw 
        elif text=='s':
            random_throw=random.choice(x)
            print random_throw
        elif text=='p':
            random_throw=random.choice(x)
            print random_throw
        else:
            print "Invalid input!"]
woooee 814 Nearly a Posting Maven

File "<stdin>", line 11
t1.append(list[temp])

"list" is a function so it should be
t1.append(list(temp))
In the future, if there is an error for a compound statement, break the statement into it's individual parts to see which part is causing the error.

woooee 814 Nearly a Posting Maven

But i want the file to call out the numbers, instead of a list

If you can't print a simple list, then you want to start at the very beginning, since counting is more complicated than printing (which is a simple loop). Some links to on-line books
http://www.greenteapress.com/thinkpy...tml/index.html
http://diveintopython.org/toc/index.html
(see "Beginner's Guide" and "Python Books") http://wiki.python.org/moin/

woooee 814 Nearly a Posting Maven

The easiest way is to use Python's count() function (and then test for a result > 0) for smaller groups of numbers. Some info on using lists. A list can also be used by element or index number. Element[0] = the number of zeros found, element[1] = number of ones, etc. which can then be multiplied by the element/index number to get the result. You can also use a dictionary, with the key equal to the number, pointing to an integer that counts the number of times the number appears.

number_list = [5, 3, 11, 3, 7, 3, 5, 5, 11, 7, 7 ]
for num in range(12):
    print "%d:%d:%d" % (num, number_list.count(num), num*number_list.count(num))
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

I want it to simply give me the logged-in users password.

Generally speaking, programs do not know passwords. A programs takes the password the user entered, converts it using some encryption algorithm, and compares to the stored password (stored in encrypted form only). Otherwise, anyone could steal any password with a simple program.