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

10 Python Functions Problems Solutions

The document presents 10 Python function problems along with their solutions. Each problem includes a function definition, a brief description, and an example output. The functions cover various tasks such as squaring a number, adding two numbers, determining even or odd, calculating factorial, and more.
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)
2 views2 pages

10 Python Functions Problems Solutions

The document presents 10 Python function problems along with their solutions. Each problem includes a function definition, a brief description, and an example output. The functions cover various tasks such as squaring a number, adding two numbers, determining even or odd, calculating factorial, and more.
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

10 Python Functions Problems with Solutions

1. Square a Number
def square(n):
return n * n

print(square(5))
# Output: 25

2. Add Two Numbers


def add(a, b):
return a + b

print(add(10, 20))
# Output: 30

3. Even or Odd
def even_odd(n):
if n % 2 == 0:
return 'Even'
return 'Odd'

print(even_odd(7))
# Output: Odd

4. Factorial
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result

print(factorial(5))
# Output: 120

5. Maximum of Two Numbers


def maximum(a, b):
return max(a, b)

print(maximum(8, 12))
# Output: 12

6. Uppercase Text
def uppercase(text):
return [Link]()

print(uppercase('python'))
# Output: PYTHON

7. Reverse String
def reverse_text(text):
return text[::-1]
print(reverse_text('Python'))
# Output: nohtyP

8. Sum of List
def total(lst):
return sum(lst)

print(total([1,2,3,4,5]))
# Output: 15

9. Remove Duplicates
def remove_duplicate(lst):
return list(set(lst))

print(remove_duplicate([1,2,2,3,3,4]))
# Output: [1, 2, 3, 4]

10. Count Vowels


def count_vowels(text):
count = 0
for ch in [Link]():
if ch in 'aeiou':
count += 1
return count

print(count_vowels('Programming'))
# Output: 3

You might also like