rohidas

Hi I am Rohidas lande.I have teaching in C.D.jain college of commerce Shrirampur .I have Nine year in teaching Experience to teach various programming langauge,script languages,databases like Java,C,C++,php,python,html,css,javascript,mysql,oracle.

Python-assignment4

Savitribai Phule Pune University T. Y. B. B. A. (C. A.) Semester-V (CBCS 2019 Pattern) CA-506: Lab Book Credits-03 Assignment 4 Working with Functions, Modules and Packages
Sr.NoAssignment name
Set-A
1
Write a recursive function which print string in reverse order.

Plz Click on Question to see Answer


def rec(s): if(len(s)==0): return s else: return rec(s[1:])+s[0] s=input("enter the string=") if(s==""): print("string should not be null") else: rev=rec(s) print(rev)


2
Write a python script using function to calculate x^y Plz Click on Question to see Answer

import math base_number=float(input("Enter the base number")) exponent=float(input("Enter the exponent")) power=math.pow(base_number,exponent) print("Power is =",power)


3
Define a function that accept two strings as input and find union and intersection of them. Plz Click on Question to see Answer

str1=input("enter first string:") str2=input("enter second string:") res=set(str1).union(str2) print(f"union of {str1} & {str2} is=",str(res)) res2=set(str1).intersection(str2) print(f"intersection of {str1} & {str2} is=",str(res2))


4
Write a recursive function to calculate sum of digits of a given input number Code. Plz Click on Question to see Answer

def sumofd(n): if n==0: return 0 else: return n%10+sumofd(n//10) num=int(input("enter number to calculate sum of digits=")) print("sum of digits=",sumofd(num))

5
Write generator function which genrate even numbers up to n Code: Plz Click on Question to see Answer

def evennum(s): b=1 while b<=s: yield b*2 b+=1 for i in evennum(20): print(i)


Set-B
1
Write a python script to generate Fibonacci terms using generator function Code.

Plz Click on Question to see Answer


def fib(num): a=0 b=1 for i in range(num): yield a a,b=b,a+b for x in fib(15): print(x)


2
Write a python script using package to calculate area and volume of cylinder and cuboids. Plz Click on Question to see Answer

File Name:-Cuboid.py def cuboid(l,w,h): area=2*(l*w+l*h+w*h) print("surface area of cuboid=",area) volume=l*w*h print("volume of cuboid=",volume) cuboid(2,3,4) File Name:-cylinder.py def cylinder(r,h): area=((2*3.14*r)*h)+((3.14*r**2)*2) print("surface area of cylinder=",area) volume=3.14*r*r*h print("volume of cylinder=",volume) cylinder(2,3) File Name:- package __init__.py from cuboid import cuboid from cylinder import cylinder package.py import mypack print(mypack.cylinder(2,4))


3
Write a python script to accept decimal number and convert it to binary and octal number using function. Plz Click on Question to see Answer

dec = int(input("Enter the number")) print("The decimal value of", dec, "is:") print(bin(dec), "in binary.") print(oct(dec), "in octal.")


4
Write a function which print a dictionary where the keys are numbers between 1 to 20. Plz Click on Question to see Answer

d=dict() for x in range(1,2 1): d[x]='' print(d)


5
Write a generator function which generates prime numbers up to n. Plz Click on Question to see Answer

def prime_generator(end): for n in range(2, end): for x in range(2, n): if n % x == 0: break else: yield n g = prime_generator(100) print(list(g))


Set-C
1
Write a progrm to illustrate function duck typing Plz Click on Question to see Answer

class python: def execute(self): print('Compiling') print('Running') print('Spell Check') print('Convention Check') class script: def code(self, ide): ide.execute() ide = python() desk = script() desk.code(ide)


Post a Comment

0 Comments