snippsat 661 Master Poster

Look at this,and se if inherits from other classes make it clearer.
What you are doing is not the way to this.

>>> class Test:
	def a(self):
		self.var1 = 5000
		print 'i am a'

		
>>> class Test1(Test):
	def b(self):
		print 'i am b'
		print 'value from class Test method a is %d' % (self.var1)

		
>>> c = Test1()
>>> c.a()
i am a
>>> c.b()
i am b
value from class Test method a is 5000
>>>
lrh9 commented: Not the same concept as what is being discussed in the topic. +0
scru commented: Use negrep sparingly +4
snippsat 661 Master Poster

It easier to help if you post some code and explain what the problem is.

snippsat 661 Master Poster

I call your code mail.py
Testet with python 2.5.4 and 2.6 run exe with no error.

If it send mail i dont know because of email2.php i guess only works for you.

from distutils.core import setup
import py2exe
import sys

if len(sys.argv) == 1:
    sys.argv.append("py2exe")

setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 1}},
       zipfile = None,
       
       # data_files = ['apple.jpg', 'cheese.jpg'],
       
       #Your file.py can use windows or console
       windows = [{"script": 'mail.py'}])
snippsat 661 Master Poster
>>> class Stuff:
	def __init__(self):
		self.a = 0.02

		
>>> x = Stuff
>>> x
<class __main__.Stuff at 0x012007E0>
>>> # you are not instance the class
>>> x = Stuff()
>>> x
<__main__.Stuff instance at 0x011FF0F8>
>>> # Here you you instance the class
>>> x.a
0.02
>>> y = Stuff()
>>> z = Stuff()
>>> a = []
>>> a.append(x.a)
>>> a.append(y.a)
>>> a
[0.02, 0.02]
>>> # here you only get 0.02 what you maybe whant to do is this
>>> class Stuff:
	def __init__(self, a):
		self.a = a

		
>>> # Now we can pass argument to the instance
>>> x = Stuff(0.02)
>>> y = Stuff(0.5)
>>> z = Stuff(40)
>>> a = []
>>> a.append(x.a)
>>> a.append(y.a)
>>> a.append(z.a)
>>> a
[0.02, 0.5, 40]

>>> b = sum(a)
>>> b
40.520000000000003

>>> print 'the sum is %.2f' % (b)
the sum is 40.52
snippsat 661 Master Poster

dint work anyway what code should i write to open the pygame window
is it import pygame?

No "import pygame" you only make pygame libary available

This code to get a pygame window open.
Seek google for pygame tutorials.

#! /usr/bin/env python  
import pygame  

screen = pygame.display.set_mode((640, 400))
 
while True:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        break
snippsat 661 Master Poster

Think input(python 3) can not take 2 values.
You can do it this way.

>>> score1 = int(input('Enter first number: '))
Enter first number: 5
>>> score2 = int(input('Enter second number: '))
Enter second number: 8
>>> average = (score1 + score2) / 2.0
>>> average
6.5
>>>
snippsat 661 Master Poster
IDLE 2.6.2      
>>> first = [ "robert", "jim", "jack" ]
>>> last = [ "smith", "white", "black" ]
>>> peeps = [ first, last ]
>>> peeps
[['robert', 'jim', 'jack'], ['smith', 'white', 'black']]
>>> prefix = ['mr', 'ms', 'mrs', 'sir']
>>> peeps.append(prefix)
>>> peeps
[['robert', 'jim', 'jack'], ['smith', 'white', 'black'], ['mr', 'ms', 'mrs', 'sir']]
>>> #append put list last

>>> peeps = [ first, last ]
>>> peeps
[['robert', 'jim', 'jack'], ['smith', 'white', 'black']]
>>> peeps.insert(1, prefix)
>>> peeps
[['robert', 'jim', 'jack'], ['mr', 'ms', 'mrs', 'sir'], ['smith', 'white', 'black']]
>>> #insert(i, list)here can you control placement

>>> #so now you can remove the insert list at placement 1
>>> peeps.pop(1)
['mr', 'ms', 'mrs', 'sir']
>>> peeps
[['robert', 'jim', 'jack'], ['smith', 'white', 'black']]
snippsat 661 Master Poster

This is just on the fly, but I tested it and it works.

Yes it work ,but this part It`s making ting a little harder and dont make much sense

for i in range(len(lucky)):
    if lucky[i] == "7":

.

>>> lucky = raw_input("Please enter an integer: ")
Please enter an integer: 7
>>> lucky
'7'
>>> #now why should we use and string in a range for loop.
>>> #dos len make it better
>>> len(lucky)
1
>>> #no
>>> for i in range(1):
	i
	
0
>>> #this line is much clearer
>>> if '7' in lucky:
>>> #dos the same as this lines
>>> for i in range(len(lucky)):
    if lucky[i] == "7":
        is_lucky = True
>>>

So if we put suggestion in this poste together with a loop an exception handling.
It would look somthing like this.

while True:   
    try:
        lucky = raw_input("Enter an integer: ")
        int(lucky.strip())
        if '7' in lucky:
            print '%s is lucky!' % (lucky)
            #break #if you want out of the loop
        else:
            print '%s is not so lucky' % (lucky)
    except ValueError:
        print 'Please number only'
snippsat 661 Master Poster

I get error "TypeError: a float is required." if I simply try "math.sqrt(n). However I think its a similar issue as the last problem I had.

>>> import math
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
>>> #Some useful stuff
>>> print (math.sqrt.__doc__)
sqrt(x)

Return the square root of x.
>>> help(math.sqrt)
Help on built-in function sqrt in module math:

sqrt(...)
    sqrt(x)
    
    Return the square root of x.

>>> #So test it out
>>> n = 9
>>> math.sqrt(n)
3.0
>>> #will it work with float number?
>>> n = 9.5
>>> type(n)
<class 'float'>
>>> math.sqrt(n)
3.082207001484488
>>> #So let make a TypeError
>>> n = [1,2,3]
>>> math.sqrt(n)
Traceback (most recent call last):
  File "<pyshell#110>", line 1, in <module>
    math.sqrt(n)
TypeError: a float is required
>>> #So math.sqrt can take integer/float but not list
>>>
snippsat 661 Master Poster

Please test your functions.

>>> def dOdd(n):
    # Returns True if odd
    for n in range(first, last):
        if n % 2 == 1:
            return True
        else:
            return False
        
>>> dOdd(5)
False
>>> dOdd(6)
False
>>> dOdd(2)
False
>>> dOdd(9)
False
>>> 
#So it not so hard to se that it dont work.
>>> n = [2,3,4,5]
>>> odd = 5
>>> def linePrinting(n, odd):
    length = len(n)
    if odd == True:
        odd = "odd"
    else:
        odd = "even"
    for x in range(1, length):
        print (n[x]), odd

        
>>> linePrinting(n, odd)
3
4
5
>>> #so think off does this do what you want?

I am not sure what you want now.
Explain very clear what you want,so it is eaiser to help.

snippsat 661 Master Poster

So you have first and last user inupt value that you use range on.
Then you have a list with number.

>>> first = 2
>>> last = 9
x = list(range(first, last)) 
[2, 3, 4, 5, 6, 7, 8]

>>># now to find odd/even you can use this
>>> x[::2]
[2, 4, 6, 8]
>>> x[1::2]
[3, 5, 7]
>>>

Or look at this solution make 2 list odd/even based on range given by user.

n_odd = []
n_even = []

first = int(input("Enter a starting integer: "))  #input 2
last = int(input("Enter an ending integer: "))    #input 8

for integer in range(first, last):
    if integer % 2 == 1:
        n_odd.append(integer)
    else:
        n_even.append(integer)

print(n_odd)
print(n_even)

'''my output-->
[3, 5, 7]
[2, 4, 6]
'''
snippsat 661 Master Poster

So lets think about what you are doing.

first = int(input("Enter a starting integer: ")) # we make it return a integer
first = first - 1
last = int(input("Enter an ending integer: "))   # we make it return a integer
last = last + 1

print (first) # test print
print (last) # test print

#so now this part work

linePrinting()  # this must have 2 argumet and you have given it 0

n = []
for integer in range(first,last):
    n.append(integer)    # here you making a list
    if dOdd(a) == True:  # you dont have a anywere
        odd = "even"
    else:
        odd = "odd"

# and you cant compare a list for opp/even
# back to idle
>>> def dOdd(n):
    # Returns True if odd
    if (n % 2) == 1:
        return True
    else:
        return False

>>> dOdd(5)
True
>>> dOdd(6)
False
>>> x = [2,3,4,5,6]
>>> dOdd(x)  #try to compare list for even/odd
Traceback (most recent call last):
  File "<pyshell#65>", line 1, in <module>
    dOdd(x)
  File "<pyshell#61>", line 3, in dOdd
    if (n % 2) == 1:
TypeError: unsupported operand type(s) for %: 'list' and 'int' #this can not take a list

So rethink what you are trying to do.

snippsat 661 Master Poster

So i used python 2.x.
Rember () for print in python3.x print('odd')

Now from idle python 3.x

>>> #Let look at type
>>> first = input("Enter a starting integer: ")
Enter a starting integer: 8
>>> 8
8
>>> type(first)
<class 'str'>
>>> #you se this is a string
>>> #so if you gone compare it to integer convert it
>>> a = int(first)
>>> a
8
>>> type(a)
<class 'int'>
>>> #now it`s a integer
>>> def odd(number):
	if number % 2 == 1:
		print ('odd')
	else:
		print ('even')

		
>>> odd(a)
even
>>>

TypeError: unsupported operand type(s) for %: 'list' and 'int'

So now you know how to check for type.
If not correct type you get a message like you got TypeError.

snippsat 661 Master Poster

For determining whether the number is odd or even I have this:

Just som traning in idle is good to do.

>>> 2 % 2
0
>>> 3 % 2
1
>>> 4 % 2
0
>>> 5 % 2
1
>>> 6 % 2
0
>>> # now you see not so hard
>>> 
>>> # we make a function that print odd/even
>>> def odd(number):
	if number % 2 == 1:
		print 'odd'
	else:
		print 'even'
		
>>> odd(2)
even
>>> odd(3)
odd
>>> #we make a function that return True/false
>>> def odd(number):
	if number % 2 == 1:
		return True
	return False

>>> odd(6)
False
>>> odd(7)
True
>>>
snippsat 661 Master Poster
>>> from random import randint
>>> a = randint (1,10,)
>>> a
2
>>> b = randint (1,10,)
>>> b
5
>>> z = a + b
>>> z
7
>>> print (a, "+", b, "=")
2 + 5 =
>>> y = input('What is the answer?   ')
What is the answer?   7
>>> y
'7'
>>> #You see now that y is a string
>>> type(y)
<class 'str'>
>>> control = True
>>> control
True
>>> while control:
    if  int(y) == z:
        print ('Correct!')
        control = False
    while int(y) != z:
        y = input('Guess again!   ')

        
Correct!
>>> z = 2
>>> while control:
    if  int(y) == z:
        print ('Correct!')
        control = False
    while int(y) != z:
        y = input('Guess again!   ')

        
>>> #you see it not work if no  "y == z"

Try this.

from random import randint
a = randint (1,10,)
b = randint (1,10,)
z = a + b
print (z)
print (a, "+", b, "=")

while True:
    y = input('What is the answer?   ')
    if z == int(y):
        print ('Correct!')
        break
    else:
        print('try again')
snippsat 661 Master Poster

+/- thing?

Yes off course.
Python is very good to use to solve math problems.

Take a look at this

#First we import math
>>> import math
Then we look at what math has to offer.
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
#Then we can test it out.
>>> math.sqrt(9)
3.0
#Dont now what all this stuff do use doc strin " __doc__" and help
>>> math.radians.__doc__
'radians(x) -> converts angle x from degrees to radians'

>>> help(math.tan)
Help on built-in function tan in module math:

tan(...)
    tan(x)
    
    Return the tangent of x (measured in radians).

>>>

def quadratic(): function is maybe ok depend off you shall do.
But the rest is just wrong.

snippsat 661 Master Poster

There are several big mistake yes.
And that use of global is not good at all.
Dont use global at all it`s ugly.

Test yout code in idle.
This is wrong.

Fraction('x \t\n')

Could be.

Fraction = ('x \t\n')

But it does not do what you want.

And this will never work.

print(fractions.Fraction(x), 'is fraction from + in +/-.') 
print(fractions.Fraction((-b-(b**2-4*a*c)**.5)/(2*a)), ' is fraction from - in +/-.')

And this what to say.

def intro2():
    global tocontinue, y, n, N, Y
    tocontinue = int(input('Again? (y/n))')
        if tocontinue == n:
            running = False
        else;
            running = True

Please test your code in idle, missing ")"(if not syntax error)

>>> tocontinue = int(input('Again? (y/n))'))
Again? (y/n))y
Traceback (most recent call last):
  File "<pyshell#33>", line 1, in <module>
    tocontinue = int(input('Again? (y/n))'))
ValueError: invalid literal for int() with base 10: 'y'

You use int here (input in python 3 return a string)

This is how it should have looked.

>>> tocontinue = input('Again? (y/n ')
Again? (y/n y
>>> tocontinue
'y'
>>>

And this i dont want to comment.

def intro():
    global running, intro3, y, Y
    while running:
        quadratic()
        answer()
        intro2()

So some more reading is smart.
Most stuff out there is for 2.x,so my advice is to use that to.
No problem to have both 2.x and 3.x installed.

For python 3.x
http://diveintopython3.org/
http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_3.0

And a lot good info on this site.

snippsat 661 Master Poster

Please use code tag so indents work.
Always read sticky post in top off a forum.

snippsat 661 Master Poster

Put this in and try again.

s=smtplib.SMTP("smtp.gmail.com",587)
s.ehlo()
s.starttls()
s.ehlo()
snippsat 661 Master Poster

There are several problem here.
Python 3.x only use input(raw_input only work for 2.x) = assign variable(can not use in = in a if statement. == Compares if the objects are equal

To get a integer to return you can do it like this.

number_of_courses = int(input ('Please enter...'))

This will not store variabls,so only last input will count.
Look at dictionary as woooee suggsest.

for number_of_courses in range (0, number_of_courses):
       major = raw_input('Enter class type') #cmsc, math, etc..
       coursenum = input('Enter course number')
snippsat 661 Master Poster

Hint.

for i in range(2, 1000):
	print i

>>> 2 % 2 == 0
True
>>> 3 % 2 == 0
False
>>> 4 % 2 == 0
True
>>> 5 % 2 == 0
False
>>>
snippsat 661 Master Poster

Print is good to use.
IDLE is good to use,to se what going on.

Just a little test

>>> import random
>>> WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone")
>>> word = random.choice(WORDS)
>>> word
'python'
>>> # So now we have a random word from tuple list

# This should give a random number from the word 'python'
>>> position = random.randrange(len(word))
>>> position
5
>>> # 5 is is "n" remember we count from 0
>>> word[position] # So this should now give "n"
'n'
>>>

Like this you can break upp the script to understand what happends.

snippsat 661 Master Poster

input was defined earlier in the code

Dont ever do that.

>>> input = 'hi'
>>> input
'hi'
>>> dir(input)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>

Now input works as a string method.
And you can use input.find(),but this is very wrong.
Dont ever use build in python method as variables.

If you not sure use "my" before so my_input.

snippsat 661 Master Poster

input is a method that is build in to python.
And you can not do this input.find

>>> input.find

Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    input.find
AttributeError: 'builtin_function_or_method' object has no attribute 'find'

>>> input('your number: ')
your number: 5
5

And comparing app,app1 to 1 is always false.

>>> app == 1
False
>>>
snippsat 661 Master Poster

What are you trying to do?

>>> first = 'stringisfun'
>>> second = 'iamsecond'
>>> app = first[0:8]
>>> app
'stringis'
>>> app1 = second[0:8]
>>> app1
'iamsecon'
>>> app + app1
'stringisiamsecon'
>>>

"and or" are used for decision control(Boolean logic)
So if you want both first and second to run that will never work.

#both test conditions are true and it print
>>> a = 4
>>> if a > 3 and a < 10:
	print 'this work'
	
this work

#if one is false it will not print
>>> if a > 3 and a > 10:
	print 'this work'


#if we use "or" only one test conditions has to be true.
>>> if a > 3 or a > 10:
	print 'this work'

this work
snippsat 661 Master Poster

Change to this.

items.Append(201,"Quit")
self.Bind(wx.EVT_MENU,self.Quit,id=201)
snippsat 661 Master Poster

Just a littel change from the good suggestion from woooee.
Type a letter:@
Never trust the user,there are always someone that dont follow instruction well.
If you want to look into this it`s called Exceptions handling
The other choice is to write the menu so that you dont need exceptions handling.

##--------------------------------------------------------------------------------------------------
## "select" is a python function and should not be used as a variable
selection = True
while selection:
    try:
        x = int(raw_input ('To convert Celsius to Farenheit, enter 1\nTo convert Farenheit to Celsius, enter 2\n'))   
        if x == 1:
            Tc_to_Tf ()
            selection = False
        elif x == 2:
            Tf_to_Tc ()
            selection = False
        else:
            print 'Only options are 1 or 2'
            
    except:
        print 'No letter please'
snippsat 661 Master Poster

Just to have some fun i build on sneekula Animal class.
Here the animal has name and it can eat and poop.

class Animal(object):
    def __init__(self, name, legs):
        self.name = name
        self.legs = legs
        self.stomach = []        
        
    def __call__(self,food):
        self.stomach.append(food)
    
    def poop(self):
        if len(self.stomach) > 0:
            return self.stomach.pop(0)
        
    def __str__(self):        
        return 'A animal named %s' % (self.name)        
        
        
cow = Animal('king', 4)
dog = Animal('flopp', 4)
print 'We have 2 animales a cow name %s and dog named %s,both have %s legs' % (cow.name, dog.name, cow.legs)
print cow  #here __str__ metod work

#We give food to cow
cow('gras')
print cow.stomach

#We give food to dog
dog('bone')
dog('beef')
print dog.stomach

#What comes inn most come out
print cow.poop()
print cow.stomach  #Empty stomach

''' output-->
We have 2 animales a cow named king and dog named flopp,both have 4 legs
A animal named king
['gras']
['bone', 'beef']
gras
[]
'''
snippsat 661 Master Poster
def Tc_to_Tf ():
    Tc = input ("What is the Celsius Temperature ?   " )
    Tf = 9.0/5.0 * Tc + 32
    return Tf

Run it an nothing happends it only return Tf
Let do something simple in idle.

IDLE 2.6.2      
>>> Tf = 50
>>> print 'The temperature is %.2f Degrees Fahrenheit' % (Tf)
The temperature is 50.00 Degrees Fahrenheit
>>>

So the only diffrence is that we put function call i a variable. Tf = Tc_to_Tf ()

snippsat 661 Master Poster

Yes dont use global find other soultion like OOP.

Think of function like a black box you can only put in variabels and return variabels out.
Then you can use your function anywhere in your code.
It dont leak out in global space.

Think always about design of your code.
Say u have a global variabel that you want to doubble opp.

global_var = 10

def doubble(x):
    return 2 * x  

new_global = doubble(global_var)
print new_global  #20

Function doubble(x) er invulnerable and you can use it anyware in you code.

snippsat 661 Master Poster

To round off decimal

IDLE 2.6.2      
>>> 0.0225
0.022499999999999999
>>> round(0.0225, 3)
0.023
>>> round(0.0225, 2)
0.02

>>> a = 15.1548
>>> print '%.2f' % a
15.15

>>> print '%.3f' % a
15.155

#Look at type
>>> s = '1.458045577554545454'
>>> type(s)
<type 'str'>

 >>> x = 1.458045577554545454
>>> type(x)
<type 'float'>

>>> y = 54
>>> type(y)
<type 'int'>

#Let try round on a string
>>> s = '1.458045577554545454'
>>> s
'1.458045577554545454'
>>> round(s, 2)

Traceback (most recent call last):
  File "<pyshell#70>", line 1, in <module>
    round(s, 2)
TypeError: a float is required

#Ok a float is required
>>> b = float(s)
>>> b
1.4580455775545456
>>> round(b, 2)
1.46
snippsat 661 Master Poster

so why doesn't it (the code above) work?

Why shoud it?
Break it thing down to understand what happends.

>>> class my_class:
	def __init__ (self):
		self.name = ' my name is hi'
		
>>> a = my_class()  #Class instance
>>> print a
<__main__.my_class instance at 0x011E23F0>
>>> 
# This only show the class instance and memory location.
# So you see now that your code can not work.

>>> a.name  #call __init__(constructor)
' my name is hi'

>>> my_list= ['a','b']
>>> for x in my_list:
	print a.name, x	
 my name is hi a
 my name is hi b

This dosent make must sense.

Just one way that give a little more sense.
----------------
my_list= ['a','b']

class my_class:    
    def __init__ (self, name):
        self.name = name       

a = my_class('Tom')

for x in my_list:
    print 'Hi %s my name is %s' % (a.name, x)

output-->
Hi Tom my name is a
Hi Tom my name is b
----------------
snippsat 661 Master Poster

try.
if shotsum > self .old_leader:

Can you post participants.txt Or just a part of it,so we can se format that goes inn.

snippsat 661 Master Poster

Yes most books tutorial are for 2.x
No problem to have both installed 2.x and 3.x installed

No problem to read 2.x books/tutorial you are learing 3.x then to,they difference is not that big.

To say it simple there are to much code 2.x that will help you that just using 3.x would not be smart.
Like this great post for beginner on this site.
http://www.daniweb.com/forums/thread20774.html

2to3 module er working great to(converts 2.x to 3.x code)
Many 3parts module works just for 2.x(wxpython,py2exe,pygame...)

Take it easy and use both 2.x and 3.x it`s thats`s the best advice.

Byte of python and dive into python has come out for 3.x
http://www.swaroopch.com/notes/Python
http://diveintopython3.org/

Books 3.x
http://www.amazon.com/Programming-Python-Complete-Introduction-Language/dp/0321680561/ref=sr_1_16?ie=UTF8&s=books&qid=1250948572&sr=1-16
http://www.amazon.com/Python-Absolute-Beginners-Tim-Hall/dp/1430216328/ref=sr_1_2?ie=UTF8&s=books&qid=1250948511&sr=1-2

snippsat 661 Master Poster

If you want to open notepad.
You can use the os module.

import os
os.system('start notepad.exe')

#Open a webpage
os.system('start iexplore.exe http://www.google.com')
snippsat 661 Master Poster

Take copy or type correct.
You have type wrong here. b = ''.join(a) ---> b = ' '.join(a) Rember space. ' '

snippsat 661 Master Poster

You can do it like this.

>>> s = '491 43140113108107 11210'
>>> s
'491 43140113108107 11210'

>>> def splitCount(s, count):
    return [''.join(x) for x in zip(*[list(s[z::count]) for z in range(count)])] 

>>> a = splitCount(s, 3)
>>> a
['491', ' 43', '140', '113', '108', '107', ' 11', '210']
>>> b = ' '.join(a)
>>> b
'491  43 140 113 108 107  11 210'
snippsat 661 Master Poster

Not much help to give you without solving it.
Look a little on this.

>>> km = raw_input('How many km? ')
How many km? 100
>>> km
'100'
>>> #As you see km is now a string
>>> type(km)
<type 'str'>
>>> #make intreger
>>> int(km)
100
>>> #100 * ??? what mystery number give miles?

For python 2.x use always raw_input(and convert to what you need)
Python 3.x has only input same as raw_input(it return a string too)

snippsat 661 Master Poster

I been using komodo ide for some years now.
Been happy with it,works fine for wxpython/pygame not that you need own ide for that.
http://www.activestate.com/komodo/

Two very good free editors is.
http://code.google.com/p/pyscripter/
http://code.google.com/p/ulipad/

snippsat 661 Master Poster

Why do I have to specify 'self' while defining the function? I usually don't do it if the function isn't in a class, then why if it is in a class

In a class a function is called a method.
An example.

class SimpleClass(object): 
      
  def SayHello(self, string):
    '''
    * This is a function,but in a class it is called a method
    * Self is the class glue,and it also transport data between metods
    * Think of self as a carrier
    '''
    print 'Hi,' + string + ' nice to see you'
    
make_object = SimpleClass()  #Class instance
make_object.SayHello('Tom')  #Call method,we give one argument(self dont count)

'''
output-->
Hi,Tom nice to see you
'''

global a
a=1

class myThread(threading.Thread):
def run(self):
print(a)
a+=1global a
a=1

class myThread(threading.Thread):
def run(self):
print(a)
a+=1

a = 1 is in the global namespace(scope)
Then global a is doing nothing.

Maybe is better to take away threading and try to understand how classes work first?

snippsat 661 Master Poster

But the problem in bumsfeld's method is that if the number I enter is huuge, then the simplified one itself be two or three characters length..so then how do I go about it?

This will work for adding integer together.

while True:
    total = sum([int(x) for x in raw_input('Enter integer')])
    if total <= 9:
        print 'Less than 10'
        break
    else:
        print total

Python has a build in function "eval"
Eval evaluates a Python expression and returns the
resulting value.

>>> eval(raw_input("Enter an arithmetic expression: "))
>>> Enter an arithmetic expression: 8/2*25-258+5896
>>> 5738
while True:
    total = eval(raw_input("Enter an expression: "))
    if total <= 9:
        print 'Less than 10'
        break
    else:
        print total
snippsat 661 Master Poster

That`s a other problem,now u are returing x.
And x is in your code is alway returing 0.

Copy my code in post #2
Run it,and u get a NameError
Take away # before global.
And now is "p" calulatet correct outside the function.

Then u start to work on "x" and why it always return 0.

snippsat 661 Master Poster

No, it doesn't show any error.

yes it dos.
To make it simple.

def test():
    # global a
    a = 5

test()
print a

This gives a NameError.
Are you using any python ide editor?

snippsat 661 Master Poster
def reduce():
    # global p
    s = raw_input("Enter a number: ")
    x = int(s)
    p = 0
    for i in s:
        p += x % 10
        x = x / 10
    return p, x   
    
reduce()
print p

Why are we getting a NameError now?
Take away # and use the not so popular global.

Read a little about local and global scope in python.

snippsat 661 Master Poster

Here i make a copy of the list,then iterating over it.
It is not a good ideƩ to delete/add somthing from a list you are iterating over.
The solution is to make a copy or new list.

mylist = ['bunnies', 'apples', 'animals', 'fruit', 'amsterdam']

for item in mylist[:]:
	if item[0] == 'a':
            mylist.remove(item)
print mylist

'''
output--->
['bunnies', 'fruit']
'''

This maybe easyer to read.

lst = ['bunnies', 'apples', 'animals', 'fruit', 'amsterdam']
    
new_lst = []
for item in lst:
        if item[0] != 'a':
            new_lst.append(item)
print new_lst

'''
output--->
['bunnies', 'fruit']
'''

Or maybe a more elegant solution with a function

def list_remove(item):   
        if item[0] == 'a':
            return False
        return True
    
lst = ['bunnies', 'apples', 'animals', 'fruit', 'amsterdam']
lst1 = [item for item in lst if list_remove(item)]
print lst1

'''
output--->
['bunnies', 'fruit']
'''
snippsat 661 Master Poster

Somthing like this.
readlines() return a list,so we just use join().
Something with a for loop should also be possibly.
See if this solve it.

>>> my_file = open('test.txt', 'r')
>>> x = my_file.readlines()
>>> x
['AATTCCGGTTT\n', 'CCTTAACCCCC']
>>> y = ''.join(x)
>>> y
'AATTCCGGTTT\nCCTTAACCCCC'
>>> finish = y.replace('\n', '')
>>> finish
'AATTCCGGTTTCCTTAACCCCC'
>>>
snippsat 661 Master Poster

Hi see if this help you.

>>> str_input = '''AATTCCGGTTT
CCTTAACCCCC'''
>>> str_input
'AATTCCGGTTT\nCCTTAACCCCC'
>>> x = str_input.replace ('\n', '')
>>> x
'AATTCCGGTTTCCTTAACCCCC'
>>>