0% found this document useful (0 votes)
1 views2 pages

Python Functions Solved Programs

The document provides a series of Python functions demonstrating various programming concepts, including calculating the area of a circle, averaging numbers, generating multiplication tables, and counting vowels and characters in strings. It also covers list manipulation, tuple analysis, linear search, and recursive algorithms for factorial and Fibonacci calculations. Each function is accompanied by example usage to illustrate its functionality.

Uploaded by

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

Python Functions Solved Programs

The document provides a series of Python functions demonstrating various programming concepts, including calculating the area of a circle, averaging numbers, generating multiplication tables, and counting vowels and characters in strings. It also covers list manipulation, tuple analysis, linear search, and recursive algorithms for factorial and Fibonacci calculations. Each function is accompanied by example usage to illustrate its functionality.

Uploaded by

mohdburhan327
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Functions - Solved Programs

1. Area of Circle using Function


import math

def area(radius):
return [Link] * radius * radius

r = int(input("Enter radius: "))


print("Area =", area(r))

2. Average of 4 Numbers using Function


def average(a,b,c,d):
return (a+b+c+d)/4

print(average(10,20,30,40))

3. Multiplication Table using Function


def table(n):
for i in range(1,11):
print(n, "x", i, "=", n*i)

table(5)

4. Count Vowels in a String


def countVowels(s):
count = 0
vowels = "aeiouAEIOU"

for ch in s:
if ch in vowels:
count += 1

return count

print(countVowels("Hello India"))

5. Count Occurrences of a Character


def countChar(s,ch):
count = 0

for c in s:
if c == ch:
count += 1

return count

print(countChar("hello world","o"))

6. Double All Values of a List


def doubleList(lst):
for i in range(len(lst)):
lst[i] = lst[i] * 2

lst = [10,20,30,40]
doubleList(lst)
print(lst)
7. Count Even and Odd Numbers in a Tuple
def countEvenOdd(t):
even = 0
odd = 0

for i in t:
if i % 2 == 0:
even += 1
else:
odd += 1

return even, odd

t = (10,21,43,20,17,19)
print(countEvenOdd(t))

8. Return Sum and Average of a List


def sumAverage(lst):
total = sum(lst)
avg = total / len(lst)
return total, avg

lst = [10,20,30,40,50]
print(sumAverage(lst))

9. Linear Search using Function


def Lsearch(lst, key):
for i in range(len(lst)):
if lst[i] == key:
return i
return -1

lst = [10,20,30,40,50]
print(Lsearch(lst,40))

10. Recursive Factorial Program


def factorial(n):
if n == 1:
return 1
return n * factorial(n-1)

print(factorial(5))

11. Recursive Fibonacci Program


def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)

for i in range(10):
print(fibonacci(i), end=" ")

You might also like