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

Practice Programs

The document contains examples of basic Python programs to demonstrate various concepts like arithmetic operations, relational operators, logical operators, bitwise operators, if/if-else statements, nested if-else statements, while loops, for loops, nested loops, functions and recursion functions. Some of the programs listed calculate things like sum, average, area of shapes, quotient, remainder, interest etc. Others demonstrate concepts like prime numbers, Armstrong numbers, Fibonacci series, pattern printing and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Practice Programs

The document contains examples of basic Python programs to demonstrate various concepts like arithmetic operations, relational operators, logical operators, bitwise operators, if/if-else statements, nested if-else statements, while loops, for loops, nested loops, functions and recursion functions. Some of the programs listed calculate things like sum, average, area of shapes, quotient, remainder, interest etc. Others demonstrate concepts like prime numbers, Armstrong numbers, Fibonacci series, pattern printing and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Basic Programs

1) Write a python program to display “Welcome to RVR & JC CE” message.


2) Write a python program to find out sum of two numbers.
3) Write a python program to find out average of three numbers.
4) Python Program to Read Two Numbers and Print Their Quotient and Remainder.
5) Write a python program to find out simple interest. (SI = [PTR] /100 )
6) Write a python program to find out sum of n integers. (Sum = [n(n+1)] /2 )
7) Write a python program to convert Fahrenheit to Celsius (C = 5 /9 x (F-32))
8) Write a python program to convert Celsius to Fahrenheit.(F = (9/5) x C+32)
9) Write a python program to calculate area of circle. (A = π r 2)
10) Write a python program to calculate area of triangle. ( Triangle = 1/2 × base × height)
11) Write a python program to perform Arithmetic operations. (add,sub,mul,div,floardiv,power)
12) Write a python program to demonstrate the use of relational operators. (<,>,==,
13) Write a python program to demonstrate the use of logical operators.
14) Write a python program to demonstrate the use of bitwise operators.
15) Write a python program to calculate the total amount of money in the piggybank, given the
coins of Rs. 10, 5, 2, 1.
16) Write a program to convert floating point into integer.
17) Write a program to convert integer into floating point.
18) Write a program to swap two numbers using a temporary variable.
19) Write a program to swap two numberswithout temporary variable.
20) Write a program to read days and convert into corresponding years, months and days.

if statement
1) Write a program to increment a number if it is positive.
2) Write a python program to read and display student bio-data. If student 10th class percentage is
below 60 % then skip it, otherwise display it.
3) Write a program to determine whether a person is eligible to vote.

if-elseStatement
1) Write a python program to determine whether a person is eligible to vote or not. If he is not
eligible, display how many years are left to be eligible.
2) Write a python program to find larger of two numbers.
3) Write a program to determine whether the character entered is a vowel or consonant.
4) Write a program to check whether the given number is even or odd.
5) Write a program to check whether given year is leap year or not
A year is a leap year if the following conditions are satisfied:
1) The year is multiple of 400.
2) The year is multiple of 4 and not multiple of 100.
if((year%4==0 and year%100!=0)||(year%400==0)
Leap Year:-One year has the length of 365 days, 5 hours, 48 minutes and 45 seconds. This is
hard to calculate with, so a normal year has been given 365 days and a leap year 366 days. In
leap years, February 29th is added as leap day, which doesn't exist in a normal year. A leap year
is every 4 years, but not every 100 years, then again every 400 years.
This year 2022 isn't a leap year. The last leap year was 2020, the next will be 2024.

if-elif-else/Nested if statement
1) Write a python program to test whether the given number is negative, positive or zero.
2) Write a python program to find out biggest of three numbers.
3) Write a python program to determine whether the character is lowercase or uppercase or digits
or special symbol.
4) Write a program that reads an integer between 1 and 7 and print the week day.
5) Write a program that reads an integer between 1 and 12 and print the month of the year.
6) A program to calculate grade based on following conditions (3 subjects)
if any subject is scored lesser than 35, failed
avg grade
Above 70 First class with distinction
60-70 First class
50-60 Second class
Below 50 Third class
S1,s2 or s3<40 Fail
7) Write a program to find out quadratic equation.

Examples:
Input :a = 1, b = 2, c = 1
Output :
Roots are real and same
-1.0

Input :a = 2, b = 2, c = 1
Output :
Roots are complex
-0.5 +i 0.5
-0.5 -i0.5

Input :a = 1, b = 10, c = -24


Output :
Roots are real and different
2.0
-12.0
8) A program for electricity bill taking different categories ofusers, different slabs in each category.
(Using nested if elsestatement).

While Loop
1. Write a program to calculate the sum and average of first 10 numbers.
2. WAP to calculate the sum of numbers from m to n. (Ex:- 30 to 50 )
3. WAP to read the numbers until -1 encountered. Also count the negatives, positives and zeros
entered by the user.
4. WAP to read the numbers until -1 encountered. Find the average of negatives numbers and
positives numbers entered by the user.
5. WAP to read the numbers until * encountered. Also count the uppercase, lowercase and
numbers entered by the user.
6. WAP to display multiplication table of a given number.
7. Write a program to calculate Exponent(x,y) value.
-Exponent value :the number of times a number is multiplied by itself.
For example, 2 to the 3rd (23) means: 2 x 2 x 2 = 8.
8. WAP to find out factorial of a given number.
Factorial number: Factorial of n is the product of all positive descending
integers. Factorial of n is denoted by n!.
Ex: 5! = 120
3! = 6
9. WAP to find the given number is prime number or not.
-Prime number:a number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11).
10. WAP to calculate sum of its digits of a given number.
11. WAP to check whether the given number is Armstrong number or not.
-Armstrong number is a number that is equal to the sum of cubes of its digits.
For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.
12. WAP to find whether the given number is Strong number or not.
Strong number is a number whose sum of factorial of each digits is equal to the
original number.
EX:- 1 is strong number because 1!= 1,
2 is strong number i.e. 2! ...
List of Strong Numbers: 1, 2, 145, 40585, ...
13. WAP to display reverse number of a given number.
14. WAP to find factors of a given number.
15. WAP to find sum of digits of a given number.
16. WAP to print the Fibonacci series.
-Fibonacci: The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the
recurrence relation Fn = Fn-1 + Fn-2
17. WAP to calculate GCD (Greatest Common Divisor) of a given numbers.
-GCD:-The highest common factor (H.C.F) or greatest common divisor (G.C.D) of two
numbers is the largest positive integer that perfectly divides the two given numbers.
For example, the GCD of 12 and 14 is 2.
18. WAP to convert decimal into Binary number
19. WAP to convert binary into decimal.

For Loop
1. WAP to calculate the avg of first n numbers using for loop
2. WAP to print Multiplication table using for loop
3. WAP to calculate factorial of a number using for loop
4. WAP to find out the given number is prime or not
5. WAP to display all the leap years from 1900-2022
6. WAP to sum the series: 1+1/2+1/3+…….1/n
7. WAP to sum the series: 1+1/22+1/32+…….1/n2
8. WAP to sum the series: 1/2+2/3+3/4+…….n/n+1
9. WAP to sum the series: 12/1+22/2+32/3+…….n2/n
10. WAP to sum of cubes of numbers from 1-n.
11. WAP to calculate sum of squares of even numbers upto a given number.
Nested Loop
1. WAP to print prime numbers between the range (ex: 100-500 prime no’s)
2. WAP to print 1 to n multiplication tables.
3. WAP to print the following patterns

12345 11111 ***** 1 1 5


12345 22222 ***** 12 22 44
12345 33333 ***** 123 333 333
12345 44444 ***** 1234 4444 2222
12345 55555 ***** 12345 55555 11111
54321 5 G GOWRI
5432 45 GO GOWR
543 345 GOW GOW
54 2345 GOWR GO
5 12345 GOWRI G

Example: Code:
5 for i in range(5,0,-1):
45 print()
345 t=i
2345 for j in range(i,6):
12345 print(t, end=" ")
t=t+1

4. WA P to demonstrate the break and continue.

Functions / Recursion Functions


1. WAP to find out factorial of a given number.
Factorial number: Factorial of n is the product of all positive descending
integers. Factorial of n is denoted by n!.
Ex: 5! = 120
3! = 6
2. WAP to sum of first 10 natural numbers.
3. WAP to calculate Exponent(x,y) value.
4. WAP to print the Fibonacci series.
Fibonacci Series: 0 1 1 2 3 5 8 13 21
5. WAP to convert decimal number into Binary number
: 5 = 101
6. WAP to convert binary into decimal.
: 101=5
7. WAP to calculate GCD (Greatest Common Divisor) of a given numbers.
-GCD:-The highest common factor (H.C.F) or greatest common divisor (G.C.D) of two
numbers is the largest positive integer that perfectly divides the two given numbers.
For example, the GCD of 12 and 14 is 2.

Strings

1. WAP to Declare, assign and print the string (Different ways).


2. WAP to Access and print characters from the string.
3. WAP to Count vowels, consonants, words and tot. characters in a string.
4. Python program to calculate the number of all possible substrings of a string
5. Python program to reverse a given string
6. Python program to remove a character from a specified index in a string
7. Python program for adding given string with a fixed message
8. Find all permutations of a given string in Python
9. WAP to Find the frequency of each character in a string
10. Print the reverse of a string that contains digits in Python
11. Python program to check if a string is palindrome or not
12. Python program to input a string and find total number uppercase and lowercase letters
13. Python program to input a string and find total number of letters and digits
14. Python program to count occurrence of a word in the given text
15. Python program for removing i-th character from a string
16. Python program to find the length of a string (different ways)
17. Python program to accept the strings which contains all vowels
18. Python program to find the least frequent character in the string
19. Python program to split and join a string
20. Python program to find words which are greater than given length k
21. How to check if a string contains special characters or not in Python?
22. Python program to find the maximum frequency character in the string

Lists
1) WAP to illustrate the following operations on a list containing integer values.
a) To display the list elements (in reverse order, even, odd position elements)
b) To display the length of the elements
c) Access an element based on index and value
d) Replace an element based on index and value
e) Insert an element based on index and value
f) Search an elements in the list
g) Append element to the list
h) Delete an element based on index and value
i) To sort list elements
j) To remove duplicate elements from the list.
k) To count the no.of times an elements occurs in the lists
l) To find the minimum and maximum values in a list

2) WAP to create two lists and display EVEN and ODD numbers separately from a list.
3) Python program to print positive or negative numbers in a list
4) WAP to print all numbers which are divisible by 2 or 4 in the List.
5) Python program to check if an element is present in list
6) WAP to illustrate union, Intersection and concatenation operations on two lists.
7) WAP to create a list from the specified start to end index of another list.
8) WAP to Create three lists of numbers, their squares and cubes.
9) WAP to remove first occurrence of a given element in the list.
10) WAP to remove all occurrences a given element from the list.
11) WAP to sort the elements of given list in Ascending and Descending Order.
12) WAP to Create two lists with first half and second half elements of a list.
13) WAP print list after removing EVEN numbers.
14) WAP print list after removing ODD numbers.
15) Check all elements of a list are the same or not in Python
16) Check all elements are unique or not in Python
17) WAP to arrange the elements in sorting order in a list without predefined functions
18) Write a python program to illustrate union, Intersection and concatenation operations on
two lists without using predefined functions.
19) Write a program to implement Stack operations
20) Write a program to implement Queue operations

You might also like