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

Working With Function 1

The document contains Python code snippets for various functions: 1) Functions to print multiplication table, find area of circle, count vowels in string, calculate sum and average of a list, and count even and odd numbers in a tuple. 2) Functions to find area of rectangle, factorial of a number, and sort an array in ascending and descending order. 3) A function to calculate simple interest with default and user-provided values.

Uploaded by

sarvesh2016.sp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Working With Function 1

The document contains Python code snippets for various functions: 1) Functions to print multiplication table, find area of circle, count vowels in string, calculate sum and average of a list, and count even and odd numbers in a tuple. 2) Functions to find area of rectangle, factorial of a number, and sort an array in ascending and descending order. 3) A function to calculate simple interest with default and user-provided values.

Uploaded by

sarvesh2016.sp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 9

CHAPTER-1

WORKING WITH FUNCTION


#Write a program for that prints the multiplication table for any integer
entered by user.
number=int(input(“Enter the number of which the user wants to print the multiplication
table:”))

count=1

print(“The Multiplication Table of:”,number)

while count<=10:

number = number*1

print(number,’x’,count,’=’,number*count)

count+=1

Output:

#.Write a python program to find area of a Circle.


def area_of_circle:

pi=3.147

area=pi*r*r

return area
radius=float(input(“Enter Radius: “))

print(“Area: “,area_of_circle(radius))

Output:
>>> Enter Radius: 5

Area: 78.675

#.Write a python program for counting vowels in string.


Def countvowels (str1):

Count=0

vowels =[‘a’,’e’,’I’,’o’,’u’]

for s in str1:

if slower() in vowels:

count+=1

return count

msg = input(“Enter Any String :”)

c= countvowels(msg)

print(“Total vowels in “, msg , “ are “,c)

Output:
Enter Any String: the quick brown fox

Total vowels in the quick brown fox are 5

#. Write a program for calculate sum and average of all number from a
given list
and return in the form of tuple.

def GetsSumAverage(mylist):

sum=0
for i in mylist:

sum+=i

avg= sum/len(mylist)

return sum,avg

mylist=[]

n= int(input(“Enter how many number :”)

for i in range (n):

num = int(input(“Enter any number :”))

mylist.append(num)

print(mylist)

sumavg = GetSumAverage(mylist)

print(“Sum = “,sumavg[0],” Average =”,sumavg[1])

Output:
#. Write a program to count how many even and odd number are
entered in

Tuple.

def CountEvenOdd(mytuple):

counteven=0

countodd=0

for i in mytuple:

if i%2==0:

counteven+=1

else:

countodd+=1

return counteven,countodd

mytuple=()

n=int(input(“Enter how many number :”))

for i in range(n):

num = int(input(“Enter how many number :”))

mytuple = mytuple +(num,)

eocount = CountEvenOdd(mytuple)

print(Even Count are :”,eocount[0],” Odd Count are :”,eocount[1])

Output:

Enter how many numbers :5

Enter any number :10

Enter any number :21


Enter any number :43

Enter any number :20

Enter any number :17

Even Count are :2 Odd Count are:4


#. Write a python program for finding area of rectangle.

def area(length, breadth):

a = length * breadth

return a

l = int(input(“Enter Length “))

b = int(input(“Enter Breadth “))

ar = area(l,b)

print(“Area of Rectangle = “,ar)

output:
Enter Length=20

Enter Breadth=10

Area of Rectangle =200

#.Write a python program for finding factorial of given number.


num = int(input(“Enter a number: “))

factorial = 1

if num < 0:

print(“Factorial does not exist for negative number”)

elif num== 0:

print(“The factorial of 0 is 1”)

else:

for i in range(1,num+1):

factorial = factorial*i
print(“The factorial of”,num,”is”,factorial)

Output:

Enter a number : 10

The factorial of 10 is3628800


#.Write an program for sorting of array in ascending and descending
order in
Python .

n=int(input(“Enter size of array\n”))

arr=list(map(int,input(“Enter elements of array\\n”).split()))

arr.sort(reverse=False)

print(“Ascending order array”)

print(*arr)

arr.sort(reverse=True)

print(“Descending order array”)

print(*arr)

Input:
Enter size of array:

Enter element of array:

42596

Output:

Ascending order array:

24569

Descending order array:

96542

#.'To display simple interest with default and given values.


def interest(principal,time=4,rate=0.09):
return principal*time*rate

print=float(input('Enter the pricipal amount:'))

print('Simple interest with default time and rate is:')

si1=interest(prin)

print('Rs.',si1)

time=int(input('Enter the duration in years:'))

rate=float(input('Enter the rate of interest:'))

print('Simple interest with given principal, time and rate is:')

si2=interest(prin,time,rate)

print('Rs.',si2)

OUTPUT:

Enter the pricipal amount:7000

Simple interest with default time and rate is:

Rs. 2520.0

Enter the duration in years:2

Enter the rate of interest:0.10

Simple interest with given principal, time and rate is:

Rs. 1400.0

You might also like