# Variable declaration
a = int(raw_input('Enter first number: '))
b = int(raw_input('Enter second number: '))
# Calculation and result
print ('The original values are a = %d b = %d' % (a, b))
temp = a
a = b
b = temp
print ('The values after swapping are a = %d b = %d' % (a, b))
# Variable declaration
a = int(raw_input('Enter first number: '))
b = int(raw_input('Enter second number: '))
# Function declaration, calculation and result
print ('The original values are a = %d b = %d' % (a, b))
def swap (a, b) :
temp = a
a = b
b = temp
print ('The values after swapping are a = %d b = %d' % (a, b))
swap (a, b)
# Variable declaration
a = int(raw_input('Enter first number: '))
b = int(raw_input('Enter second number: '))
# Function declaration, calculation and result
print ('The original values are a = %d b = %d' % (a, b))
def swap (a, b) :
temp = a
a = b
b = temp
print ('The values after swapping are a = %d b = %d' % (a, b))
swap (a, b)
# Variable declaration
a = int(raw_input('Enter first number: '))
b = int(raw_input('Enter second number: '))
# Function declaration, calculation and result
print ('In main the original values are a = %d b = %d' % (a, b))
print ('In main the address of a is %x and address of b is %x' % (a, b))
def swap (a, b) :
print ('In swap the address in a is %x and b is %x' % (a, b))
temp = a
a = b
b = temp
print ('The values after swapping are a = %d b = %d' % (a, b))
swap (a, b)
print ('In main the values after swapping are a = %d b = %d' % (a, b))
# Variable declaration
a = int(raw_input('Enter first number: '))
b = int(raw_input('Enter second number: '))
# Function declaration, calculation and result
print ('In main the value of a = %d b = %d' % (a, b))
def doooo (a, b) :
a = a+10
b = b+10
doooo (a, b)
print ('In main the value of a = %d b = %d' % (a, b))
# Variable declaration
a = int(raw_input('Enter first number: '))
b = int(raw_input('Enter second number: '))
# Function declaration, calculation and result
print ('In main the value of a = %d b = %d' % (a, b))
print ('In main the addresses are a = %s b = %s' % (hex(id(a)), hex(id(b))))
def doooo (a, b) :
print ('In doooo the addresses are a = %s b = %s' % (hex(id(a)), hex(id(b))))
a = a+10
b = b+10
doooo (a, b)
print ('In main the value of a = %d b = %d' % (a, b))
# Variable declaration
a = int(raw_input('Enter first number '))
b = int(raw_input('Enter second number '))
# Function declaration, calculation and result
def add (a, b) :
x = a+b
return x
som = add (a, b)
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 '))
# Function declaration, calculation and result
def greater (a, b) :
if a>b :
big = a
else :
big = b
return big
great = greater (a, b)
print ('The greater number is %d' % great)
# Variable declaration
a = int(raw_input('Enter first number '))
b = int(raw_input('Enter second number '))
c = int(raw_input('Enter third number '))
# Function declaration, calculation and result
def greater (a, b, c) :
if a>b :
if a>c :
big = a
else :
big = c
else :
if b>c :
big = b
else :
big = c
return big
great = greater (a, b, c)
print ('The greatest number is %d' % great)
# Variable declaration
n = int(raw_input('Enter any number '))
# Function declaration, calculation and result
def summate (n) :
i = 1
total = 0
while i <= n :
total = total + i
i = i+1
return total
sumn = summate (n)
print ('Sum of first %d natural numbers is %d' % (n, sumn))
# Variable declaration
n = int(raw_input('Enter any number '))
# Function declaration, calculation and result
def sumofdigit (n) :
sum = 0
while n > 0 :
sum = sum + n%10
n = n/10
return sum
result = sumofdigit (n)
print ('Sum of digits of %d is %d' % (n, result))
# Variable declaration
n = int(raw_input('Enter any number '))
sum = n
# Function declaration, calculation and result
def sumofdigit (n, sum) :
while sum>=10 :
sum = 0
while n>0 :
sum = sum + n%10
n = n/10
n = sum
return sum
result = sumofdigit (n, sum)
print ('Sum of digits of %d is %d' % (n, result))
# Variable declaration
n = int(raw_input('Enter any number '))
# Function declaration, calculation and result
def checkprime (n) :
flag = 1
i = 2
while i<n and flag :
if n%i == 0 :
flag = 0
i = i+1
return flag
result = checkprime (n)
if result :
print ('%d is Prime ' % n)
else :
print ('%d is Composite ' % n)
# Variable declaration
n = int(raw_input('Enter any number '))
# Function declaration, calculation and result
def checkprime (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),
checkprime (n)
# Variable declaration
n = int(raw_input('Enter any number '))
# Function declaration, calculation and result
def makethird (n) :
first = 0
second = 1
count = 3
print ('%d terms of Fibonacci series are ' % n)
print ('%d %d ' % (first, second)),
while count<=n :
third = first + second
first = second
second = third
print (' %d ' % third),
count = count + 1
makethird (n)
# Variable declaration
n = int(raw_input('Enter any number '))
# Function declaration, calculation and result
def makethird (n) :
first = 0
second = 1
third = 0
print ('Fibonacci series up to %d is ' % n)
print first,
while third<=n :
print (' %d ' % second),
third = first + second
first = second
second = third
makethird (n)