import sys
n = int(raw_input("\nEnter value to n : "))
for i in range(1,n+1):
sys.stdout.write("%8d"%(i))
import sys
import numpy
import math
print "\n--------------------------------"
print " X Y "
print "--------------------------------"
for x in numpy.arange(1.0,3.0+0.2,0.2):
y = 1.36*math.sqrt(1+x+x*x*x)+ pow(x,1.0/4) + math.exp(x)
sys.stdout.write("\n %6.2f %6.2f"%(x,y))
print "\n--------------------------------"
k = int(raw_input("\nEnter the number : "))
kfact = 1
for i in range(1,k+1):
kfact = kfact * i
print k," factorial is ",kfact
n = int(raw_input("\nEnter value to N : "))
s = 0
for i in range(1,n+1):
term = 0
for j in range(1,i+1):
term = term + j
s = s + term
print "\nSum of the series S = ",s
import numpy
import sys
for x in numpy.arange(-1.5,1.5+0.5,0.5):
for y in numpy.arange(0,3.0+1.0,1.0):
z = 3*x*x + 2*y*y*y - 25.5
sys.stdout.write("\n\nValue of y(%0.2f,%0.2f) = %6.2f"%(x,y,z))
n = int(raw_input("\nEnter value to N : "))
s = 0
i = 1
while i <= n:
s = s + i
i = i + 2
print "\nSum of odd integers = ",s
import sys
print "\nInteger divisible by 7"
n = 7
for i in range(1,50+1):
sys.stdout.write("%8d"%(n))
n = n + 7
import sys
n = int(raw_input("\nEnter the end value N : "))
print "\nIntegers not divisible by 7"
for k in range(1,n+1):
r = k % 7
if r != 0:
sys.stdout.write("%8d"%(k))
n = int(raw_input("\nEnter a positive integer : "))
q = n
s = 0
while q > 0:
r = q % 10
s = s + r
q = q/ 10
print "\nSum of digits = ",s
n = int(raw_input("\nEnter an integer number : "))
q = n
s = 0
while q > 0:
r = q % 10
s = s + r*r*r
q = q/10
if n == s:
print "\n",n," is an Armstrong number"
else:
print "\n",n," is not an Armstrong number"
n = int(raw_input("\nEnter an integer number : "))
q = n
rn = 0
while q > 0:
r = q % 10
rn = rn*10 + r
q = q/10
print "\n",n," is reversed as ",rn
n = int(raw_input("\nEnter an integer number : "))
q = n
rn = 0
while q > 0:
r = q % 10
rn = rn*10 + r
q = q/10
while rn > 0:
r = rn % 10
#There is no switch statement in python
if r == 1:
print "One"
else:
if r == 2:
print "Two"
else:
if r == 3:
print "Three"
else:
if r == 4:
print "Four"
else:
if r == 5:
print "Five"
else:
if r == 6:
print "Six"
else:
if r == 7:
print "Seven"
else:
if r == 8:
print "Eight"
else:
if r == 9:
print "Nine"
else:
print "Zero"
rn = rn/10
flag = 0
n = int(raw_input("\nEnter a positive integer : "))
for k in range(2,n/2+1):
if flag == 0:
r = n % k
if r == 0:
flag = 1
if flag == 0:
print "\n",n," is a prime number"
else:
print "\n",n," is not a prime number"
import sys
n = int(raw_input("\nEnter the final term of the series : "))
n1 = 0
n2 = 1
sys.stdout.write("%8d%8d"%(n1,n2))
newterm = n1 + n2
while newterm <= n:
sys.stdout.write("%8d"%(newterm))
n1 = n2
n2 = newterm
newterm = n1 + n2
x = float(raw_input("\nEnter x in radians : "))
n = int(raw_input("\nEnter end term power (n) : "))
s = 0
term = x
i = 1
while i <= n:
s = s + term
term = (term*x*x*(-1))/((i+1)*(i+2))
i = i + 2
print "\nSum of the series = ",s
x = float(raw_input("\nEnter x in radians : "))
s = 0
term = 1
i = 0
while i <= n:
s = s + term
term = (term*x*x*(-1))/((i+1)*(i+2))
i = i + 2
print "\nSum of the series = ",s
import sys
import math
s = 0
dr = 1
sign = 1
term = 1.0/dr * sign
while (math.fabs(term) >= 1.0e-4):
s = s + term
dr = dr + 2
sign = sign * (-1)
term = (1.0/dr) * sign
pie = s * 4
sys.stdout.write("\nValue of pie is %0.2f"%(pie))
import sys
n = int(raw_input("\nEnter value to N : "))
s = 0
for i in range(1,n+1):
s = s + 1.0/i
sys.stdout.write("\nSum of series = %8.4f"%(s))
import sys
n = int(raw_input("\nHow many lines ? "))
for l in range(1,n+1):
for i in range(1,n-l+1):
sys.stdout.write(" ")
m = l
for j in range(1,l+1):
sys.stdout.write("%6d"%(m))
m = m + 1
m = m - 2
for k in range(1,l):
sys.stdout.write("%6d"%(m))
m = m - 1
sys.stdout.write("\n")
import sys
n = int(raw_input("\nHow many rows ? "))
print "\n\t\t\t\t PASCAL TRIANGLE\n"
m = 1
for l in range(0,n):
for i in range(40-3*l,0,-1):
sys.stdout.write(" ")
for j in range(0,l+1):
if j == 0 or l == 0:
m = 1
else:
m = (m*(l-j+1))/j
sys.stdout.write("%6d"%(m))
sys.stdout.write("\n")
import sys
for i in range(1,5+1):
sys.stdout.write("\n\nMultiplication table for %d\n"%(i))
for j in range(1,10+1):
sys.stdout.write("\n%4d x %2d = %4d"%(j,i,j*i))
sys.stdout.write("\n\nPress any key to continue...")
n = int(raw_input("\nEnter the binary number : "))
q = n
s = 0
k = 0
while q > 0:
r = q % 10
s = s + r * pow(2,k)
q = q/10
k = k + 1
print "\nThe decimal number is : ",s
flag = 0
k = 0
n = int(raw_input("\nEnter the decimal number : "))
q = n
rbi = 0
while q > 0:
r = q % 2
if r == 0 and flag == 0:
k = k + 1
else:
flag = 1
rbi = rbi *10 + r
q = q/2
q = rbi
bi = 0
while q > 0:
r = q % 10
bi = bi * 10 + r
q = q/10
if q == 0:
for i in range(1,k+1):
bi = bi * 10
print "\nThe binary number is ",bi