0% found this document useful (0 votes)
663 views29 pages

Python Programs - Oswal

The document summarizes 65 Python programs covering a range of concepts like recursion, functions, lists, strings, conditionals, loops, patterns, etc. The programs include examples to find Fibonacci sequence, Pascal's triangle, even/odd numbers in a list, Armstrong numbers, prime numbers, factorial, sorting, searching, and more. Most programs have the source code and corresponding output for each concept demonstrated.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
663 views29 pages

Python Programs - Oswal

The document summarizes 65 Python programs covering a range of concepts like recursion, functions, lists, strings, conditionals, loops, patterns, etc. The programs include examples to find Fibonacci sequence, Pascal's triangle, even/odd numbers in a list, Armstrong numbers, prime numbers, factorial, sorting, searching, and more. Most programs have the source code and corresponding output for each concept demonstrated.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 29

Class – 12 : Oswal Book Python Program Execution By Anitha.

1. Python program using recursion to display Fibonacci sequence.

Source Code

Output

2. Implementing Pascal’s Triangle.

Source Code:

Output:
3. Write a program to read a number. If the number is even print half the number otherwise print the
next number. End your program by printing “Thank You!”

Source Code:

Output:

5. Write a program that reads three numbers and prints them in ascending order.

Source Code:

Output:
6. Write a python program to print the even numbers from a given list using function .

Source Code:

Output:
7. Write a python program to input ‘n’ numbers and to search any number from the list.

Source Code:

Output:

8. Write a python program to input any number and to check whether given number is Armstrong or
not.

Source Code:

Output
9. Write a python function program to sum all the number in a list.

Source Code:

Output:

10. Write a python program to check whether the given number is composite or not.

Source Code:

Output:

11. Write a python program to reverse a string.

Source Code:

Method - 1
Method - 2

Output:

12. Write a python program to accept two integers from the user and prints a message saying first
number is divisible by second number or if it is not.

Source Code:

Output:

13. Write a function or method to display the area of circle.

Source Code:

Output:
15. Write a program to display a menu for calculating area of a circle and perimeter of a circle.

Source Code:

Output:

16. To check the given year is leap year or not.

Source Code:

Output:
18. Python program that uses a function which takes two string arguments and returns the string
comparision result of the two passed string.

Source Code:

Output:

19. Python program to check the given key is already exists in a dictionary.

Source Code:
Output:

22. Write a void function that receives a 4 digit number and calculates the sum of squares of first two
digits of the number and last two digits of the number. (eg) if 1230 is passed as argument then
function should calculate 144+900=1044.

Source Code:

Output:

24. Program to search the number of times a particular number occurs in a list.

Source Code:
Output:

25. Program to find the sum of series with cubes of first ‘n’ natural numbers.

Source Code:

Output:

26. To find factors of a number.

Source Code:

Output:
27. To print the multiplication table of a number entered by the user.

Source code:

Output:

28. Function to calculate volume of a box with approximate default values for its parameters. Your
function should have the following input parameters.

i) Length of box
ii) width of box
iii) Height of box
Source Code:

Output:
30. Program to find the L.C.M of two numbers entered by the user.

Source Code:

Output:

31. Program to find the largest number among three numbers.

Source Code:

Output:
33. To check whether the number entered by the user is positive, negative or zero.

Source Code:

Output:

34. To find the prime numbers between lower limit and upper limit.

Source Code:

Output:
35. To create a simple calculator that can add, subtract, multiply or divide depending upon the input
from the user.

Source Code:

Output:
36. To calculate the average of numbers in a given list.

Source Code:

Output:

37. Program to reverse a number entered by the user.

Source Code:

Output:
38. Write a function that takes a number as argument and calculate cube of it. The function does not
return a value. If there is no value passed to the function in function call, the function should calculate
cube of 2.

Source Code:

Output:

39. Write a function that,


i) Ask the user to input a diameter of circle in inches.
ii) Set a variable called radius to one half of that number.
iii) Calculate the area of circle.
iv) Print the area of circle with appropriate unit.
v) Return the same amount as the output of the function.

Source Code:

Output:
40. Program that reads a file and capitalizes the first letter of every word in the file.

Source Code:

Output:

41. To check whether the string is Palindrome or not using recursion.

Source Code:

Output:
43. Floyd’s Triangle

Source code:

Output:

44. To remove punctuation from string.

Source Code:

Output:
45. Write a python program to determine how many times a given letter occurs in the string recursively.

Source Code:

Output:

46. Write a python program that takes a string and counts the occurrence of each word in the given
sentences.

Source Code:

Output:
48. Python Program to count the lowercase and uppercase letter in a string.

Source Code:

Output:

49. Write a python program to calculate discount based on the sale amount using nested if else.

Discount rates are:


Amount Discount
0-500 2%
500-1500 5%
1500-2500 10%
Above 2500 15%
Source Code:
Output:

50. Factorial of a number using recursion.

Source Code:

Output:

51. Python program to find largest element in the list using function.

Source Code:
Output:

52. Python program to create a list with even and odd numbers.

Source Code:

Output:

53. https://www.youtube.com/watch?v=ZwJzhsAGKfA
54. To find the smallest K-digit number divisible by X, Number X and K are given.

Source Code:

Output:

55. To read a number n and print an inverted star pattern of the required size.

Source Code:

Output:

Source Code:
Output:

56. Python Program to Find the Sum of the Series: 1 + 1/2 + 1/3 + ….. + 1/N.

Source Code:

Output:

57. Python program to form an integer that has the number of digits at the ten's place and the most
significant digit in the one's place.

Source Code:

Output:
58. Python program to print all words with even length in the given string.

Source Code:

Output:

59. Python program to split the string into words and also print the length of the each word.

Source Code:

Output:
60. Python program to find the area of the triangle.

Source Code:

Output:

61. Python program to count the number of vowels present in given string using sets.

Source Code:

Output:
62. Python program to change the decimal number into binary number.

Source Code:

Output:

63. Python program to print full triangle pyramid pattern using an Asterisk(star).

Source Code:

Output:
64. To check whether the given number is odd or even recursively.

Source Code:

Output:

65. Program to find sum of elements of a list recursively.

Source Code:

Output:
66. To form an integer that has the number of digits at the ten's place and the most significant digit in
the one's place.

Source Code:

Output:

You might also like