You are on page 1of 5

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment: 1.3

Student Name: Ashutosh Kumar UID: 21BCS7473


Branch: CSE Section/Group: 815B
Semester: 4TH Date of Performance: 24/03/2023
Subject Name: Python Subject Code: 21CSH214

Aim: Program to demonstrate the use of functions and passing different types of arguments functions.

Q1) Write a Python program to calculate area of 10 different circles if pie=22/7 and the radius of circle
entered by user using function, parameterized function , return type with parameterized function.

Source code:
pi=22/7
def ar1():
area1=pi*r*r
print("Area with Simple function",area1)
def ar2():
area2=pi*r*r
return area2
def ar3(radius):
area3=pi*radius*radius
print("Area with Parameter function",area3)
def ar4(radius):
area4=pi*radius*radius
return area4
while(i<=10):
r = int(input("\nEnter Radius: "))
r2=ar2()
print("Area with Simple Return type",r2)
ar3(r)
r3=ar4(r)
print("Area with Parameterized Return type",r3)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Q2) Write a python program to print Multiplication tables from2 to 20 whether tablevalues entered by
user using Simple Function,Parameterized Function ReturnTypewith function and return type with
parameterized Functions.
Source code:
def table1():
print("With Simple Function")
for i in range (2,21):
print(n,' * ',i,' = ',n*i)
def table2():
return n*i
def table3(num):
print("With Parameterized Function")
for i in range (2,21):
print(num,' * ',i,' = ',num*i)
def table4(num,i):
return num*i
n=int(input("Enter a number to print its table form 2 to 20: "))
table1()
table3(n)
print("With Simple Return Function")
for i in range(2,21):
res1=table2()
print(n,' * ',i,' = ',res1)
print("With Parameterized Return Function")
for i in range(2,21):
res2=table4(n,i)
print(n,' * ',i,' = ',res2)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Q3(codechef) Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the
transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal
transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US.
Calculate Pooja's account balance after an attempted transaction.

Source code:
inp_str = input().split(' ')
wtd_amnt = int(inp_str[0])
bal_amnt = float(inp_str[1])
lst_dgt = float(inp_str[0][len(inp_str[0]) - 1])
if lst_dgt in (5, 0) and wtd_amnt != 0:
if wtd_amnt + 0.5 <= bal_amnt :
print('%.2f' %(bal_amnt - wtd_amnt - 0.5))
else: print('%.2f' %(bal_amnt))
else: print('%.2f' %(bal_amnt))
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like