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

Oppe Python Questions

The document provides sample Python questions and solutions, including functions for checking palindromes, finding prime numbers less than a given number, generating Fibonacci sequences, calculating character frequency, and implementing bubble sort. Each function is presented with its definition and logic. The examples demonstrate basic programming concepts and algorithms in Python.
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)
6 views2 pages

Oppe Python Questions

The document provides sample Python questions and solutions, including functions for checking palindromes, finding prime numbers less than a given number, generating Fibonacci sequences, calculating character frequency, and implementing bubble sort. Each function is presented with its definition and logic. The examples demonstrate basic programming concepts and algorithms in Python.
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

OPPE 2 Python – Sample Questions & Solutions

1) Palindrome Checker

def is_palindrome(s):

s = [Link]().replace(" ", "")

return s == s[::-1]

2) Primes Less Than N

def primes_less_than(n):

primes = []

for num in range(2, n):

if all(num % i != 0 for i in range(2, int(num**0.5) + 1)):

[Link](num)

return primes

3) Fibonacci Sequence

def fibonacci(n):

a, b = 0, 1

result = []

for _ in range(n):

[Link](a)

a, b = b, a + b

return result

4) Character Frequency

from collections import Counter

s = input("Enter a string: ")

freq = Counter(s)
5) Bubble Sort

def bubble_sort(arr):

n = len(arr)

for i in range(n):

for j in range(0, n - i - 1):

if arr[j] > arr[j + 1]):

arr[j], arr[j + 1] = arr[j + 1], arr[j]

return arr

You might also like