print [int(str(a)+str(b)+str(c)) for a in range(1,10) for b in range(0,10) for c in range(1,10) if a==c]
2015-05-21
print [str(a)+str(b)+str(c) for a in range(1,10) for b in range(1,10) for c in range(1,10) if a==c]
2015-05-21
sum = 0
x = 1
while x<100:
if x%2==1:
sum=sum+x
x=x+1
print sum
x = 1
while x<100:
if x%2==1:
sum=sum+x
x=x+1
print sum
2015-05-21
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2015-05-20
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-05-20
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-05-20
def greet(x='world'):
print 'Hello,'+x+'.'
greet()
greet('Bart')
print 'Hello,'+x+'.'
greet()
greet('Bart')
2015-05-20
def move(n, a, b, c):
if (n == 1):
print a + '-->' + c
return
move(n-1, a, c, b)
print a + '-->' + c
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
if (n == 1):
print a + '-->' + c
return
move(n-1, a, c, b)
print a + '-->' + c
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
2015-05-20
import math
def quadratic_equation(a, b, c):
d = b*b - 4*a*c
return (-b + math.sqrt(d)) / (2.0*a) , (-b - math.sqrt(d)) / (2.0*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
d = b*b - 4*a*c
return (-b + math.sqrt(d)) / (2.0*a) , (-b - math.sqrt(d)) / (2.0*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-05-20