Practice Programs
Practice Programs
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
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
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
Strings
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