0% found this document useful (0 votes)
4 views

Labassignment 8 MS

Uploaded by

notrealbybit
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Labassignment 8 MS

Uploaded by

notrealbybit
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB ASSIGNMENT-8

NAME: Mayank
ROLLNO:23124062
BRANCH:IT A3B
QUES 1
def fib(n):
if (n==0):
return 0
elif (n==1):
return 1
else:
return (fib(n-1)+ fib(n-2))

n=int(input("Enter n : "))
print(fib(n+1))
for i in range(n):
print(fib(i),end=(""))

OUTPUT:

QUES 2
def sum(list):
if len(list)==0:
return 0
else:
return list[0]+sum(list[1:])

list=[1,2,3,4,5]
sum=sum(list)
print("The sum is : ",sum)

OUTPUT:

QUES 3
import math

def distance(x1,y1,x2,y2):
return math.sqrt((x2-x1)**2 +(y2-y1)**2)

def radius(x_c,y_c,x_p,y_p):
return distance(x_c,y_c,x_p,y_p)

def area(radius):
return math.pi * radius **2
OUTPUT:

QUES 4
def fun(list):
original_id=id(list)
for i in range(len(list)):
list.append(list[i]*2)
return original_id

list=[1,2,3]
original_id=fun(list)
print("Original list : ",list)
print("ID of original list : ",original_id)
print("ID of the processed list : ",id(list))

OUTPUT:

QUES 5
n=10
result=0

def sum():
global result
for i in
range(1,n+1):
result+=i
print(result)

sum()

OUTPUT:

QUES 6
def rev_number(num):
def reverse():
nonlocal num
rev = 0
while num >0:
rev = rev * 10 + num % 10
num //=10
num = rev
print(num)

reverse()
number = int(input("Enter a number:
")) rev_number(number)

OUTPUT:

You might also like