Python Tuple Practice Programs, Exercises

Python tuple practice programs help students to improve their logic building.

1). Python tuple program to create a tuple with 2 lists of data.
Input lists:
list1 = [4, 6, 8]
list2 = [7, 1, 4]
Output= ((4, 7), (6, 1), (8, 4))

2). Python tuple program to find the maximum value from a tuple.
Input = (41, 15, 69, 55)
Output = 69

3). Python tuple program to find the minimum value from a tuple.
Input = (36,5,79,25)
Output = 5

4). Python tuple program to create a list of tuples from a list having a number and its square in each tuple.
Input = [4,6,3,8]
Output = [ (4, 16), (6, 36), (3, 27), (8, 64) ]

5). Python tuple program to create a tuple with different datatypes.
Output= ( 2.6, 1, ‘Python’, True, [5, 6, 7], (5, 1, 4), {‘a’: 123, ‘b’: 456})

6). Python tuple program to create a tuple and find an element from it by its index no.
Input = (4, 8, 9, 1)
Index = 2
Output = 9

7). Python tuple program to assign values of tuples to several variables and print them.
Input = (6,7,3)
Variables = a,b,c
Output:
a, 6
b, 7
c, 3

8). Python tuple program to add an item to a tuple.
Input= ( 18, 65, 3, 45)
Output=(18, 65, 3, 45, 15)

9). Python tuple program to convert a tuple into a string.
Input = (‘s’, ‘q’, ‘a’, ‘t’, ‘o’, ‘o’, ‘l’, ‘s’)
Output = Sqatools

10). Python tuple program to get the 2nd element from the front and the 3rd element from the back of the tuple.
Input = (‘s’, ‘q’, ‘a’, ‘t’, ‘o’, ‘o’ ,’l’, ‘s’)
Output=
q
o

11). Python tuple program to check whether an element exists in a tuple or not.
Input = ( ‘p’ ,’y’, ‘t’, ‘h’, ‘o’, ‘n’)
P in A
Output=
True

12). Python tuple program to add a list in the tuple.
Input:
L=[12,67]
A=(6,8,4)
Output:
A=(6,8,4,12,67)

13). Python tuple program to find sum of elements in a tuple.
Input:
A=(4,6,2)
Output:
12

14). Python tuple program to add row-wise elements in Tuple Matrix
Input:
A = [[(‘sqa’, 4)], [(‘tools’, 8)]]
B = (3,6)
Output:
[[(‘sqa’, 4,3)], [(‘tools’, 8,6)]]

15). Python tuple program to create a tuple having squares of the elements from the list.
Input = [1, 9, 5,  7, 6]
Output = (1, 81, 25, 49, 36)

16). Python tuple program to multiply adjacent elements of a tuple.
Input = (1,2,3,4)
Output =  (2,6,12)

17). Python tuple program to join tuples if the initial elements of the sub-tuple are the same.
Input:
[(3,6,7),(7,8,4),(7,3),(3,0,5)]
Output:
[(3,6,7,0,5),(7,8,4,3)]

18). Python tuple program to convert a list into a tuple and multiply each element by 2.
Input = [12,65,34,77]
Output = (24, 130, 68, 154)

19). Python tuple program to remove an item from a tuple.
Input:
A=(p,y,t,h,o,n)
Output: (p,y,t,o,n)

20). Python tuple program to slice a tuple.
Input:
A=(5,7,3,4,9,0,2)
Output:
(5,7,3)
(3,4,9)

21). Python tuple program to find an index of an element in a tuple.
Input:
A=(s,q,a,t,o,o,l,s)
Index of a?
Output = 2

22). Python tuple program to find the length of a tuple.
Input:
A=(v,i,r,a,t)
Output=
5

23). Python tuple program to convert a tuple into a dictionary.
Input:
A=((5,s),(6,l))
Output = { s: 5, l: 6 }

24). Python tuple program to reverse a tuple.
Input = ( 4, 6, 8, 3, 1)
Output= (1, 3, 8, 6, 4)

25). Python tuple program to convert a list of tuples in a dictionary.
Input = [ (s, 2), (q, 1), (a, 1), (s, 3), (q, 2), (a, 4) ]
Output ={ s: [ 2, 3 ], q: [ 1, 2 ], a: [ 1 ,4 ] }

26). Python tuple program to pair all combinations of 2 tuples.
Input :
A=(2,6)
B=(3,4)
Output
[ (2, 3), (2, 4), (6, 3), (6, 4), (3, 2), (3, 6), (4, 2), (4, 6) ]

27). Python tuple program to remove tuples of length i.
Input = [ (2, 5, 7), (3, 4), ( 8, 9, 0, 5) ]
i=2
Output= [ (2, 5, 7), ( 8, 9, 0, 5) ]

28). Python tuple program to remove tuples from the List having an element as None.
Input = [(None, 2), (None, None), (5, 4), (1,6,7)]
Output= { (5, 4), (1, 6, 7) }

29). Python tuple program to remove Tuples from the List having every element as None.
Input = [(None,), (None, None), (5, 4), (1,6,7),(None,1)]
Output = [(5, 4), (1,6,7),(None,1)]

30). Python tuple program to sort a list of tuples by the first item.
Input = [ (1, 5), (7, 8), (4, 0), (3, 6) ]
Output = [ (1, 5), (3, 6), (4, 0), (7, 8) ]

31). Python tuple program to sort a list of tuples by the second item.
Input = [ (1, 5), (7, 8), (4, 0), (3, 6) ]
Output = [ (4, 0), (1, 5), (3, 6), (7, 8) ]

32). Python tuple program to sort a list of tuples by the length of the tuple.
Input = [(4, 5, 6), ( 6, ), ( 2, 3), (6, 7, 8, 9, 0 ) ]
Output=
[(6,),(2,3),(4,5,6),(6,7,8,9,0)]

33). Python tuple program to calculate the frequency of elements in a tuple.
Input=
(a, b, c, d, b, a, b)
Output=
{ a:2, b:3, c:1, d:1 }

34). Python tuple program to filter out tuples that have more than 3 elements.
Input=
[ (1, 4), (4, 5, 6), (2, ), (7, 6, 8, 9), (3, 5, 6, 0, 1) ]
Output= [(7, 6, 8, 9), (3, 5, 6, 0, 1)]

35). Python tuple program to assign the frequency of tuples to each tuple.
Input=
[ (s,q), (t, o, o, l), (p, y), (s, q) ]
Output= {(‘s’, ‘q’): 2, (‘t’, ‘o’, ‘o’, ‘l’): 1, (‘p’, ‘y’): 1}

36). Python program to find values of tuples at ith index number.
Input=
[ (1, 2, 3), (6, 5, 4), (7, 6, 8), (9, 0, 1) ]
I = 3
Output= (9,0,1)

37). Python tuple program to test whether a tuple is distinct or not.
Input=
(1,2,3,4)
(3,4,5,4,6,3)
Output=
Tuple is distinct
Tuple is not distinct

38). Python tuple program to convert a tuple to string datatype.
Input=
A=(4,1,7,5)
Output=
The given tuple is (4,1,7,5)

39). Python tuple program to remove empty tuples from a list of tuples.
Input=
[ (”,), (‘a’, ‘b’), (‘a’, ‘b’, ‘c’), (‘d’), () ]
Output=
[ (‘a’, ‘b’), (‘a’,  ‘b’,  ‘c’),  (‘d’) ]

40). Python tuple program to sort a tuple by its float element.
Input=
[(3,5.6),(6,2.3),(1,1.8)]
Output=
[(1,1.8),(6,2.3),(3,5.6)]

41). Python tuple program to count the elements in a list if an element is a tuple.
Input=
[1,6,8,5,(4,6,8,0),5,4)]
Output=
4

42). Python tuple program to multiply all the elements in a tuple.
Input=
(5,4,3,1)
Output=
60

43). Python tuple program to convert a string into a tuple.
Input=
“Sqatools”
Output=
(S,q,a,t,o,o,l,s)

44). Python tuple program to convert a tuple of string values to a tuple of integer values.
Input=
( ‘4563’, ’68’, ‘1,’ )
Output=
( 4563, 68, 1)

45). Python tuple program to convert a given tuple of integers into a number.
Input=
(4, 5, 3, 8)
Output=
4538

46). Python tuple program to compute the element-wise sum of tuples.
Input=
(1, 6, 7)
(4, 3, 0)
(2, 6, 8)
Output=
(7, 15, 15)

47). Python tuple program to convert a given list of tuples to a list of lists.
Input=
A=[(1,5),(7,8),(4,0)]
Output =
[ [1, 5], [7, 8], [4, 0] ]

48). Python tuple program to find all the tuples that are divisible by a number.
Input=
[(10,5,15),(25,6,35),(20,10)]
Output=
[(10,5,15),(20,10)]

49). Python tuple program to find tuples having negative elements.
Input=
[ (1, 7), (-4, -5), (0, 6), (-1, 3) ]
Output=
[(-4,-5),(-1,3)]

50). Python tuple program to find the tuples with positive elements.
Input=
[ (1, 7), (-4, -5), (0, 6), (-1, 3) ]
Output=
[ (1, 7), (0, 6) ]

51). Python tuple program to remove duplicates from a tuple.
Input=
(6, 4, 9, 0, 2, 6, 1, 3, 4)
Output=
(6, 4, 9, 0, 2, 1, 3)

52). Python tuple program to extract digits from a list of tuples.
Input=
[ (6, 87, 7), (4, 53), (11, 28, 3) ]
Output=
[ 1, 2, 3, 4, 5, 6, 7, 8 ]

53). Python tuple program to multiply ith element from each tuple from a list of tuples.
Input=
[ (4, 8, 3), (3, 4, 0), (1, 6, 2) ]
i=1
Output=
192

54). Python tuple program to flatten a list of lists into a tuple.
Input=
[ [s], [q], [a], [t], [o], [o], [l], [s] ]
Output=
(s, q, a, t, o, o, l, s)

55). Python tuple program to flatten a tuple list into a string.
Input=
[ (s, q, a), (t, o), (o, l, s) ]
Output=
‘s q a t o o l s’

56). Python tuple program to convert a tuple into a list by adding the string after every element of the tuple.
Input=
A=(1, 2, 3, 4), b=’sqatools’
Output=
[1, “sqatools”, 2, “sqatools”, 3, “sqatools”, 4, “sqatools”]

57). Write a program to convert a tuple to tuple pair.
Input=
(1, 2, 3)
Output=
[ (1, 2), (1, 3) ]

59). Python tuple program to convert a list of lists to a tuple of tuples.
Input=
[ [‘sqatools’], [‘is’], [‘best’]]
Output=
( (‘sqatools’), (‘is), (‘best’) )

60). Python tuple program to extract tuples that are symmetrical with others from a list of tuples.
Input=
[ (a, b, c), (d, e), (c, b, a) ]
Output=
(a, b, c)

61). Python tuple program to return an empty set if no tuples are symmetrical.
Input=
[(1, 5, 7), (3, 4), (4, 9, 0)]
Output=
set()

62). Python tuple program to remove nested elements from a tuple.
Input=
( ‘s’, ‘q’, ‘a’, (‘t’, ‘o’, ‘o’, ‘l’, ‘s’), ‘i’, ‘s’, ‘b’, ‘e’, ‘s’, ‘t’ )
Output=
(‘s’, ‘q’, ‘a’, ‘i’, ‘s’, ‘b’, ‘e’, ‘s’ ,’t’)

63). Python tuple program to sort a tuple by the maximum value of a tuple.
Input=
[ (1, 5, 7), (3, 4, 2), (4, 9, 0) ]
Output=
[ (4, 9, 0), (1, 5, 7), (3, 4, 2) ]

64). Python tuple program to sort a list of tuples by the minimum value of a tuple.
Input=
[(1,5,7),(3,4,2),(4,9,0)]
Output=
[(4,9,0),(1,5,7),(3,4,2)]

65). Python tuple program to concatenate two tuples.
Input=
(‘s’,’q’,’a)
(‘t’,’o’,’o,’l’)
Output=
((‘s’,’q’,’a),(‘t’,’o’,’o,’l’))

66). Python tuple program to order tuples by external list.
Input=
a=[(‘very’,8),(‘i’,6),(‘am,5),(‘happy’,0)]
List=[‘i’,’am’,’very’,’happy’]
Output=
[(‘i’,6),(‘am’,5),(‘very’,8),(‘happy’,0)]

67). Python tuple program to find common elements between two lists of tuples.
Input=
A=[(1,5),(4,8),(3,9)]
B=[(9,3),(5,6),(5,1),(0,4)]
Output=
{(3,9),(1,5)}

68). Python tuple program to convert a binary tuple to an integer.
Input=
A=(1,0,0)
Output=
4
Explanation=
2^2+0+0=4

69). Python tuple program to count the total number of unique tuples.
Input=
[ (8, 9), (4, 7), (3, 6), (8, 9) ]
Output=
3

70). Python tuple program to calculate the average of the elements in the tuple.
Input=
(5, 3, 9, 6)
Output=
5.75

71). Python tuple program to swap tuples.
Input=
A=(7,4,9)
B=(3,)
Output=
A=(3,)
B=(7,4,9)

72). Python tuple program to check the type of the input and return True if the type is a tuple and False if it is not a tuple.
Input=
A=( 7, 4, 9, 2, 0 )
Output=
True

73). Python tuple program to find the last element of a tuple using negative indexing.
Input=
A=(‘p’,y’,’t’,’o’,’n’)
Output=
n

Python File Handling Programs, Exercises

Python File Handling Programs refers to the process of manipulating files on a computer using Python programming language. In Python, you can perform various operations on files such as reading, writing, appending, and deleting files.

To perform file handling in Python, you first need to open a file. The open() function is used to open a file. It takes two parameters – the file name (along with the path, if necessary) and the mode in which you want to open the file.

1). Python Program How to read a file in reading mode.

2). Python file program to overwrite the existing file content.

3). Python file program to append data to an existing file.

4). Python file program to get the file’s first three and last three lines.

5). Python file program to get all the email ids from a text file.

6). Python file program to get a specific line from the file.

7). Python file program to get odd lines from files and append them to separate files.

8). Python file program to read a file line by line and store it in a list.

9). Python file program to find the longest word in a file.

10). Python file program to get the count of a specific word in a file.

11). Python file program to read a random line from a file.

12). Python file program to copy the file’s contents to another file after converting it to lowercase.

13). Python file program to copy the file’s contents to another file after converting it to uppercase.

14). Python file program to count all the words from a file.

15). Python file program to sort all the lines File as per line length size.

16). Python file program to consider a text file as a DB file and store all the student information in a text file.

17). Python file program to create n number of text files with given strings.

18). Python file program to generate text files with all alphabets.  e.g. A.txt , B.txt, C.txt….. Z.txt

19). Python file program to get all odd and even length words in two lists.

20). Python file program to get all mobile numbers from a file. e.g each mobile number size should be 10.

21). Python file program to get a list of all domains from a file. e.g. .com, .au, .in

22). Python file program to compare two files.

23). Python file program to count the number of lines in a file.

24). Python file program to get the file size of a file.

25). Python file program to write a tuple to a file.

26). Python file program to check whether a file is closed or not.

27). Python file program to extract characters from a text file into a list.

28). Python file program to read the data of two of the files created and add it to a new file.

29). Python file program to count the total number of characters in a file.

30). Python file program to count the total number of Uppercase characters in a file.

31). Python file program to count the total number of Lowercase characters in a file.

32). Python file program to count the total number of digits in a file.

33). Python file program to count the total number of special characters in a file.

34). Python file program to find the cursor position in a file.

35). Python file program to move the cursor to a specific position in a file.

36). Python file program to read the content of the file in reverse order.

37). Python file program to read a file and display each word separated by @.

38). Python file program to count the total number of vowels in a file.

39). Python file program to count the total number of consonants in a file.

40). Python file program to remove all the lines that contain the character ‘t’ in a file and write it to another file.

41). Python file program to display words from a file that has less than 5 characters.

42). Python file program to replace space by an underscore in a file.

For reference here python input/output official documentation.

Python If else Practice Programs, Exercises

Python If else practice programs help beginners to get expertise in conditional programming login. The if-else statement is a conditional statement in programming. It executes a set of instructions if a particular condition is true, and another set of instructions if the condition is false.

1). Python program to check given number is divided by 3 or not.

2). If else program to get all the numbers divided by 3 from 1 to 30.

3). If else program to assign grades as per total marks.
marks > 40: Fail
marks 40 – 50: grade C
marks 50 – 60: grade B
marks 60 – 70: grade A
marks 70 – 80: grade A+
marks 80 – 90: grade A++
marks 90 – 100: grade Excellent
marks > 100: Invalid marks

4). Python program to check the given number divided by 3 and 5.

5). Python program to print the square of the number if it is divided by 11.

6). Python program to check given number is a prime number or not.

7). Python program to check given number is odd or even.

8). Python program to check a given number is part of the Fibonacci series from 1 to 10.

9). Python program to check authentication with the given username and password.

10). Python program to validate user_id in the list of user_ids.

11). Python program to print a square or cube if the given number is divided by 2 or 3 respectively.

12). Python program to describe the interview process.

13). Python program to determine whether a given number is available in the list of numbers or not.

14). Python program to find the largest number among three numbers.

15). Python program to check any person eligible to vote or not
age > 18+ : eligible
age < 18: not eligible

16). Python program to check whether any given number is a palindrome.
Input: 121
Output: palindrome

17). Python program to check if any given string is palindrome or not.
Input: ‘jaj’
output = palindrome

18). Python program to check whether a student has passed the exam. If marks are greater than 35 students have passed the exam.
Input = Enter marks: 45
Output = Pass

19). Python program to check whether the given number is positive or not.
Input = 20
Output = True

20). Python program to check whether the given number is negative or not.
Input = -45
Output = True

21). Python program to check whether the given number is positive or negative and even or odd.
Input = 26
Output = The given number is positive and even

22). Python program to print the largest number from two numbers.
Input:
25, 63
Output = 63

23). Python program to check whether a given character is uppercase or not.
Input = A
Output = The given character is an Uppercase

24). Python program to check whether the given character is lowercase or not.
Input = c
Output = True

25). Python program to check whether the given number is an integer or not.
Input = 54
Output = True

26). Python program to check whether the given number is float or not.
Input = 12.6
Output = True

27). Python program to check whether the given input is a string or not.
Input = ‘sqatools’
Output = True

28). Python program to print all the numbers from 10-15 except 13
Output:
10
11
12
14

29). Python program to find the electricity bill. According to the following conditions:
Up to 50 units rs 0.50/unit
Up to 100 units rs 0.75/unit
Up to 250 units rs 1.25/unit
above 250 rs 1.50/unit
an additional surcharge of 17% is added to the bill
Input = 350
Output = 438.75

30). Python program to check whether a given year is a leap or not.
Input = 2000
Output = The given year is a leap year

31). Python Python program to check whether the input number if a multiple of two print “Fizz” instead of the number and for the multiples of three print “Buzz”. For numbers that are multiples of both two and three print “FizzBuzz”.
Input = 14
Output = Fizz
Input = 9
Output = Buzz
Input = 6
Output = FizzBuzz

32). Python program to check whether an alphabet is a vowel.
Input = A
Output = True

33). Python program to check whether an alphabet is a consonant.
Input = B
Output = True

34).  Python program to convert the month name to the number of days.
Input = February
Output = 28/29 days

35). Python program to check whether a triangle is equilateral or not. An equilateral triangle is a triangle in which all three sides are equal.
Input:
Enter the length of the sides of the triangle
A=10
B=10
C=10
Output = True

36). Python program to check whether a triangle is scalene or not. A scalene triangle is a triangle that has three unequal sides.
Input:
Enter the length of the sides of the triangle
A=10
B=15
C=18
Output = True

37). Python program to check whether a triangle is isosceles or not. An isosceles triangle is a triangle with (at least) two equal sides.
Input:
Enter the length of the sides of the triangle
A=10
B=15
C=10
Output = True

38). Python program that reads month and returns season for that month.
Input = February
Output = Summer

39). Python program to check whether the input number is a float or not if yes then round up the number to 2 decimal places.
Input = 25.3614
Output = 25.36

40). Python program to check whether the input number is divisible by 12 or not.
Input = 121
Output = True

41). Python program to check whether the input number is a square of 6 or not.
Input = 37
Output = False

42). Python program to check whether the input number is a cube of 3 or not.
Input = 27
Output = True

43). Python program to check whether two numbers are equal or not.
Input:
A=26,B=88
Output = The given numbers are not equal

44). Python program to check whether the given input is a complex type or not.
Input:
a=5+6j
Output: True

45). Python program to check whether the given input is Boolean type or not.
Input:
a=True
Output = The given variable is Boolean

46). Python program to check whether the given input is List or not.
Input:
a=[1,3,6,8]
Output = True

47). Python program to check whether the given input is a dictionary or not.
Input:
A={‘name’:’Virat’,’sport’:’cricket’}
Output = True

48). Python program to check the eligibility of a person to sit on a roller coaster ride or not. Eligible when age is greater than 12.
Input = 15
Output = You are eligible

49). Python program to create 10 groups of numbers between 1-100 and find out given input belongs to which group using python nested if else statements.
Input= 36
Output = The given number belongs to 4th group

50). Python program to find employees eligible for bonus. A company decided to give a bonus of 10% to employees. If the employee has served more than 4 years. Ask the user for years served and check whether an employee is eligible for a bonus or not.
Input = Enter Years served: 5
Output = You are eligible for a bonus

51). Take values of the length and breadth of a rectangle from the user and check if it is square or not using the python if else statement.
Input:
Length= 4
Breadth= 5
Output = It is not a square

52). A shop will give a 10% discount if the bill is more than 1000, and 20% if the bill is more than 2000. Using the python program Calculate the discount based on the bill.
Input = 1500
Output = Discount amount: 150

53). Python program to print the absolute value of a number defined by the user.
Input = -1
Output = 1

54). Python program to check the student’s eligibility to attend the exam based on his/her attendance. If attendance is greater than 75% eligible if less than 75% not eligible.
Input = Enter attendance: 78
Output = You are eligible

55). Python program to check whether the last digit of a number defined by the user is divisible by 4 or not.
Input = 58
Output = The last digit is divisible by 4

56). Python program to display 1/0 if the user gives Hello/Bye as output.
Input = Enter your choice: Hello
Output = 1
Input = Enter your choice: Bye
Output = 0

57). Python program to accept the car price of a car and display the road tax to be paid according to the following criteria:
Cost price<500000 –> tax:15000
Cost price<1000000 –> tax:50000
Cost price<1500000 –> tax:80000
Input = Car Price: 1200000
Output = Tax payable: 50000

58). Using a python program take input from the user between 1 to 7 and print the day according to the number. 1 for Sunday 2 for Monday so on.
Input = Enter number: 7
Output = Saturday

59). Python program to accept the city name and display its monuments (take Pune and Mumbai as cities).
Input = Enter city name: Pune
Output:
Shaniwar vada
Lal mahal
Sinhgad fort

60). Python program to check whether the citizen is a senior citizen or not. An age greater than 60 than the given citizen is a senior citizen.
Input = Enter age: 70
Output = The given citizen is a senior citizen

61). Python program to find the lowest number between three numbers.
Input:
A=45
B=23
C=68
Output = 23

62). Python program to accept the temperature in Fahrenheit and check whether the water is boiling or not.
Hint: The boiling temperature of water in Fahrenheit is 212 degrees
Input = Enter temperature: 190
Output = Water is not boiling

63). Python program to accept two numbers and mathematical operations from users and perform mathematical operations according to it.
Input:
A=30
B=45
Operation = +
Output = 75

64). Python program to accept marks from the user allot the stream based on the following criteria.
Marks>85: Science
Marks>70: Commerce
35<Marks<70: Arts
Marks<35: Fail
Input = Marks: 88
Output = Science

Python Basic Programs, Exercises

Python basic programs contains Python Programming Examples with all native Python data type, mathematical operations on Python Variables. Typecasting of Python Variables and get understanding of Python Fundamentals.

1). Python Program to add two integer values.

2). Python Program to subtract two integer values.

3). Python program to multiply two numbers.

4). Python program to repeat a given string 5 times.
Input :
str1 = “SQATools”
Output :
“SQAToolsSQAToolsSQAToolsSQAToolsSQATools” 

5). Python program to get the Average of given numbers.
Formula: sum of all the number/ total number
Input:
a = 40
b = 50
c = 30
Output :
Average = 40

6). Python program to get the median of given numbers.
Note: all the numbers should be arranged in ascending order
Formula : (n+1)/2
n = Number of values
Input : [45, 60, 61, 66, 70, 77, 80]
Output:  66

7). Python program to print the square and cube of a given number.
Input :
num1 = 9
Output :
Square = 81
Cube =   729

8). Python program to interchange values between variables.
Input :
a = 10
b = 20
Output :
a = 20
b = 10

9). Python program to solve this Pythagorous theorem.
Theorem : (a2 + b2 = c2)

10). Python program to solve the given math formula.
Formula : (a + b)2 = a^2 + b^2 + 2ab

11). Python program to solve the given math formula.
Formula : (a – b)2 = a^2 + b^2 – 2ab

12). Python program to solve the given math formula.
Formula : a2 – b2 = (a-b)(a+b)

13). Python program to solve the given math formula.
Formula : (a + b)3 = a3 + 3ab(a+b) + b3 

14). Python program to solve the given math formula.
Formula : (a – b)3 = a3 – 3a2b + 3ab2 – b3

15). Python program to calculate the area of the square.
Formula : area = a*a

16). Python program to calculate the area of a circle.
Formula = PI*r*r
r = radius
PI = 3.14

17). Python program to calculate the area of a cube.
Formula = 6*a*a

18). Python program to calculate the area of the cylinder.
Formula = 2*PI*r*h + 2*PI*r*r

19). Python program to check whether the given number is an Armstrong number or not.
Example: 153 = 1*1*1 + 5*5*5 + 3*3*3

20). Python program to calculate simple interest.
Formula = P+(P/r)*t
P = Principle Amount
r = Anual interest rate
t = time

21). Python program to print the current date in the given format
Output: 2023 Jan 05
Note: Use the DateTime library

22). Python program to calculate days between 2 dates.
Input date : (2023, 1, 5) (2023, 1, 22)
Output: 17 days

23). Python program to get the factorial of the given number.

24). Python program to reverse a given number.

25). Python program to get the Fibonacci series between 0 to 50.

26). Python program to check given number is palindrome or not.

27). Python program to calculate compound interest.

28). Python program to check the prime number.

29). Python program to check leap year.

30). Python program to check for the anagram.
Note: rearrangement of the letters of a word to another word, using all the original letters exactly once.

31). Python program to generate random numbers.

32). Python program to generate a random string with a specific length.

33). Python program to get the current date.

34). Python program to convert Decimal to Binary.

35). Python program to find the sum of natural numbers.

36). Python program to find HCF.

37). Python program to find LCM.

38). Python program to find the square root of a number.
Note: Use the math library to get the square root.

39). Python program to calculate the volume of a sphere.
Formula = (4/3*pi*r^2)
r = radius
pi = 3

40). Python program to perform mathematical operations on two numbers.

Python Functional, Programs And Excercises

A Python function is a sequence of statements that executes a specific task. A function can take arguments, which are the information passed to the function when it is called. Functions can also return values, which are the result of executing the function.

1). Python function program to add two numbers.

2). Python function program to print the input string 10 times.

3). Python function program to print a table of a given number.

4). Python function program to find the maximum of three numbers.

Input: 17, 21, -9
Output: 21

5). Python function program to find the sum of all the numbers in a list.
Input : [6,9,4,5,3]
Output: 27

6). Python function program to multiply all the numbers in a list.
Input : [-8, 6, 1, 9, 2]
Output: -864

7). Python function program to reverse a string.
Input: Python1234
Output: 4321nohtyp

8). Python function program to check whether a number is in a given range.
Input : num = 7, range = 2 to 20
Output: 7 is in the range

9). Python function program that takes a list and returns a new list with unique elements of the first list.
Input : [2, 2, 3, 1, 4, 4, 4, 4, 4, 6]
Output : [2, 3, 1, 4, 6 ]

10). Python function program that take a number as a parameter and checks whether the number is prime or not.
Input : 7
Output : True

11). Python function program to find the even numbers from a given list.
Input : [1, 2, 3, 4, 5, 6, 7, 8, 9]
Output : [2, 4, 6, 8]

12). Python function program to create and print a list where the values are squares of numbers between 1 to 10.
Input: 1 to 10
Output: 1, 4, 9, 16, 25, 36, 49, 64, 81

13). Python function program to execute a string containing Python code.

14). Python function program to access a function inside a function.

15). Python function program to find the LCM of two numbers.
Input: 12, 20
Output: 60

16). Python function program to calculate the sum of numbers from 0 to 10.
Output: 55

17). Python function program to find the HCF of two numbers.
Input: 24 , 54
Output: 6

18). Python function program to create a function with *args as parameters.
Input: 5, 6, 8, 7
Output: 125 216 512 343

19). Python function program to get the factorial of a given number.
Input: 5
Output: 120

20). Python function program to get the Fibonacci series up to the given number.
Input: 10
Output: 1 1 2 3 5 8 13 21 34

21). Python function program to check whether a combination of two numbers has a sum of 10 from the given list.
Input : [2, 5, 6, 4, 7, 3, 8, 9, 1]
Output : True

1, 22). Python function program to get unique values from the given list.
Input : [4, 6, 1, 7, 6, 1, 5]
Output : [4, 6, 1, 7, 5]

23). Python function program to get the duplicate characters from the string.
Input: Programming
Output: {‘g’,’m’,’r’}

24). Python function program to get the square of all values in the given dictionary.
Input = {‘a’: 4, ‘b’ :3, ‘c’ : 12, ‘d’: 6}
Output = {‘a’: 16, ‘b’ : 9, ‘c’: 144, ‘d’, 36}

25). Python function program to create dictionary output from the given string.
Note: Combination of the first and last character from each word should be
key and the same word will the value in the dictionary.
Input = “Python is easy to Learn”
Output = {‘Pn’: ‘Python’, ‘is’: ‘is’, ‘ey’: ‘easy’, ‘to’: ‘to’, ‘Ln’: ‘Learn’}

26). Python function program to print a list of prime numbers from 1 to 100.

27). Python function program to get a list of odd numbers from 1 to 100.

28). Python function program to print and accept login credentials.

29). Python function program to get the addition with the return statement.

30). Python function program to create a Fruitshop Management system.

31). Python function program to check whether the given year is a leap year.

32). Python function program to reverse an integer.

33). Python function program to create a library management system.

34). Python function program to add two Binary numbers.

35). Python function program to search words in a string.

36). Python function program to get the length of the last word in a string.

37). Python function program to get a valid mobile number.

38). Python function program to convert an integer to its word format.

39). Python function program to get all permutations from a string.

40). Python function program to create a function with **kwargs as parameters.

41). Python function program to create a function local and global variable.