# Calculation and result
pi = 3.141
num = int(raw_input('Enter your favorite number: '))
print ('You have entered your favorite number as %d' % num)
c = raw_input('Enter your favorite character: ')
print ('You have entered your favorite character as %c' % c)
print ('The value of pi is %.3f ' % pi)
# Variable declaration
a = int(raw_input('Enter first number '))
b = int(raw_input('Enter second number '))
# Calculation
som = a+b
# Result
print ('The sum of %d + %d = %d ' % (a, b, som))
# Variable declaration
a = int(raw_input('Enter first number '))
b = int(raw_input('Enter second number '))
# Calculation and result
if a>b :
print ('The greater number is %d ' % a)
else :
print ('The greater number is %d ' % b)
# Variable declaration
a = int(raw_input('Enter first number '))
b = int(raw_input('Enter second number '))
# Calculation and result
if a==b :
print ('Both numbers are equal ')
else :
if a>b :
print ('The greater number is %d ' % a)
else :
print ('The greater number is %d ' % b)
# Variable declaration
a = int(raw_input('Enter first number '))
b = int(raw_input('Enter second number '))
c = int(raw_input('Enter third number '))
# Calculation and result
if a>b :
if a>c :
print ('The greatest number is %d ' % a)
else :
print ('The greatest number is %d ' % c)
else :
if b>c :
print ('The greatest number is %d ' % b)
else :
print ('The greatest number is %d ' % c)
# Variable declaration
n = int(raw_input('Enter any number '))
# Calculation and result
print ('Counting upto %d ' % n)
for i in range (1, n+1) :
print ('%d ' % i),
# Variable declaration
n = int(raw_input('Enter any number '))
# Calculation and result
print ('Even numbers upto %d ' % n)
for i in range (2, n+1, 2) :
print ('%d ' % i),
# Variable declaration
n = int(raw_input('Enter any number '))
# Calculation and result
print ('Odd numbers upto %d ' % n)
for i in range (1, n+1, 2) :
print ('%d ' % i),
# Variable declaration
n = int(raw_input('Enter any number '))
# Calculation and result
print ('Number line upto %d ' % n)
for i in range (-n, n+1) :
print ('%d ' % i),
# Variable declaration
n = int(raw_input('Enter any number '))
sum = 0
# Calculation
for i in range (1, n+1) :
sum = sum + i
# Result
print ('Sum of %d natural numbers is %d ' % (n, sum))
# Variable declaration
n = int(raw_input('Enter any number '))
# Calculation and result
print ('The factors of %d are ' % n)
for i in range (1, n+1) :
if n%i == 0 :
print ('%d ' % i),
# Variable declaration
n = int(raw_input('Enter any number '))
# Calculation and result
print ('The first 10 multiples of %d are ' % n)
for i in range (1, 11) :
print ('%d X %d = %d ' % (n, i, n*i))
# Variable declaration
n = int(raw_input('Enter any number '))
i = 1
sum = 0
# Calculation
print ('The sum of digits of %d is' % n),
while n > 0 :
sum = sum + n%10
n = n/10
# Result
print ('%d' % sum)
# Variable declaration
n = int(raw_input('Enter any number '))
flag = 1
# Calculation
for i in range (2, n) :
if flag == 1 :
if n%i == 0 :
flag = 0
# Result
if flag :
print ('%d is Prime ' % n)
else :
print ('%d is Composite ' % n)
# Variable declaration
n = int(raw_input('Enter any number '))
first = 0
second = 1
count = 3
# Calculation and result
print ('%d Fibonacci terms are ' % n)
print ('%d %d ' % (first, second)),
while count<=n :
third = first + second
first = second
second = third
print ('%d ' % third),
count = count + 1
# Variable declaration
n = int(raw_input('Enter any number '))
sum = n
# Calculation
print ('Sum of digits of %d is' % n),
while sum>=10 :
sum = 0
while n>0 :
sum = sum + n%10
n = n/10
n = sum
# Result
print ('%d' % sum)
# Variable declaration
n = int(raw_input('Enter any number '))
# Calculation and result
print ('Prime numbers upto %d are ' % n)
for num in range (2, n+1) :
flag = 1
for i in range (2, num) :
if num % i == 0 :
flag = 0
if flag :
print ('%d ' % num),
# Variable declaration
n = int(raw_input('Enter a number '))
# Calculation and result
for lin in range (1, n+1) :
for count in range (1, lin+1) :
print ('%d ' % count),
print
# Variable declaration
n = int(raw_input('Enter a number '))
# Calculation and result
for lin in range (1, n+1) :
for count in range (lin, 2*lin) :
print ('%d ' % count),
print
# Variable declaration
n = int(raw_input('Enter a number '))
# Calculation and result
for lin in range (1, n+1) :
for blk in range (1, n-lin+1) :
print ' ',
for up in range (1, lin+1) :
print ('%d' % up),
down = lin-1
while down>0 :
print ('%d' % down),
down = down-1
print
# Variable declaration
n = int(raw_input('Enter a number '))
# Calculation and result
for lin in range (1, n+1) :
for blk in range (1, n-lin+1) :
print ' ',
for up in range (lin, 2*lin) :
print ('%d' % (up%10)),
down = 2*lin-2
while down>=lin :
print ('%d' % (down%10)),
down = down-1
print