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

Practice Programs

Uploaded by

cs.harimohan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Practice Programs

Uploaded by

cs.harimohan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

UNIT-1

1. Write a program to enter two numbers and perform all arithmetic


operations.

2. Write a program to enter marks of five subjects and calculate total,


average and percentage.

3. Write a program to enter length in centimeter and convert it into


meter and kilometre.

4.Write a program to find area of a circle. (Take radius as input from


user).

5. Write a Program to Swap Two Numbers (entered by user) without


using third variable.

6. Write a Program to calculate simple interest.


Simple Interest = (P x T x R)/100
Where,
P is the principle amount
T is the time and
R is the rate

Take P, T & R from user as Input.

7. Write a Program for compound interest.


A = P(1 + R/100)t
Compound Interest = A – P
Where,
A is amount
P is principle amount
R is the rate and
T is the time span
UNIT-2

1. Python Program to take three numbers from the user and print the
greatest number.

2. Write a program to print whether given number is even or odd.

3. Write a program to print any person is eligible for vote or not (age

should not less then 18 for voting).

4. Write a Program to check Armstrong Number.

A positive integer of n digits is called an Armstrong number


of order n (order is number of digits) if.
abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + ....
\ Input: 153
Output: Yes
153 is an Armstrong number.
1*1*1 + 5*5*5 + 3*3*3 = 153

5. Write a program to check whether a number entered by user is Prime


or not.

6. Write a program to calculate factorial of a number entered by user.

7. Python Program to check whether a given number is a palindrome.

8. Write a program to print all Prime numbers between given range.

9. Write a program to print n-th Fibonacci number.


10. Write a program to check if a given number is Fibonacci number?

11. Write a program for Sum of squares of first n natural numbers.

Ex: if Input: N = 4
Then Output: 30
12 + 22 + 32 + 42 = 1 + 4 + 9 + 16 = 30

12. Write a program for cube sum of first n natural numbers.

13. WAP to print given pattern

14. WAP to print given pattern


15. Write a program to take an integer N as an input and display the
pattern.

Input
5
Output
*
**
***
****
*****
****
***
**
*
UNIT-3
Programs of String:

1. Write a program to print every character of a string entered by user in


a new line using loop.

2. Write a program to find the length of string entered by user without


using len function.

3. Write a program to check if the letter is present in the word or not.

4. Write a program to check if the word is present in the sentence or not.

5. Write a program to find the first and the last occurrence of the letter
in a String.

6. Write a program that takes your full name as input and displays the
abbreviations of the first and middle names except the last name
which is displayed as it is. For example, if your name is Robert Brett
Roser, then the output should be R.B.Roser.

7. Write a program to find the number of vowels, consonants, digits and


white space characters in a string.

8. Write a program to make a new string with all the consonants deleted
from a string.

9. Write a Python program to get a single string from two given strings,
separated by a space and swap the first two characters of each string.
Sample Input: abc xyz
Sample Output: xyc abz
10. Write a Python program to get a string from a given string where all
occurrences of its first char have been changed to '$', except the first
char itself.
Sample Input: restart
Sample Output: resta$t

11. Write a Python program to add 'ing' at the end of a given string
(length should be at least 3). If the given string already ends with 'ing'
then add 'ly' instead. If the string length of the given string is less than
3, leave it unchanged.
Sample String : 'abc'
Expected Result : 'abcing'
Sample String : 'string'
Expected Result : 'stringly'

12. Write a Python program to change a given string to a new string


where the first and last chars have been exchanged.

13. Write a Python program to remove the nth index character from a
nonempty string.

14. Write a Python program to remove the characters which have odd
index values of a given string.

15. Write a Python program to Removal all characters from a string


except integers.
Programs of List and Tupple:

1. Write a program to sum all the items in a list.

2. Write a program to multiply all the items in a list.

3. Write a program to get the largest and smallest number from a list.

4. Write a Python program to count the number of strings from a given


list of strings, where string length is 2 or more and the first and last
characters are same.
Sample List : ['abc', 'xyz', 'aba', '1221']
Expected Result : 2

5. Write a Python program to remove duplicate elements from a list.

6. Write a Python program to print the numbers of a specified list after


removing even numbers from it.

7. Write a Program to Extract elements from list with Frequency greater


than K (entered by user).

8. Write a Python program to change the position of every n-th value to


the (n+1)th in a list.
Sample list: [0,1,2,3,4,5]
Expected Output: [1, 0, 3, 2, 5, 4]

9. Write a Python program to check if each number is prime in a given


list of numbers. Return True if all numbers are prime otherwise False.
Sample Data:
([0, 3, 4, 7, 9]) -> False
([3, 5, 7, 13]) -> True
([1, 5, 3]) -> False

10. Write a Python program to get the 4th element from the last
element of a tuple.

11. Write a Python program to find repeated items in a tuple.

12. Write a Python program to compute the element-wise sum of given

tuples.
Original lists:
(1, 2, 3, 4)
(3, 5, 2, 1)
(2, 2, 3, 1)
Element-wise sum of the said tuples:
(6, 9, 8, 6)
Programs of Functions:

1. Write a Python function to sum all the numbers in a list.

2. Write a python program to calculate area of 5 different circles using


Simple Function (Parameterized Function with return type). Given the
pie = 22/7 and radius of the circles entered by user.

3. Write a python program to print Multiplication tables from 2 to 20


whether table values entered by user using Simple Function,
Parameterized Function , Return Type with function and return type
with parameterized Functions .

4. Write a Python function that takes two lists and returns True if they
have at least one common member.

5. Write a Python function that accepts a string and counts the number
of upper and lower case letters.
Sample Input : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
UNIT-4

1. WAP to create a file named "sample.txt" with the following content:

Hello, this is a sample text file.

Line 2: Adding some more content.

2. Write a Python program to open the file "sample.txt" and print its
content line by line.

3. Open the "sample.txt" file in append mode and add the following lines
to it:

Line 3: Appending content to the file.

Line 4: Another appended line.

4. Print the updated content of the "sample.txt" file.

5. Create a new file named "numbers.txt" and write the numbers 1 to 10,
each on a new line.

6. Write a program to read the numbers from "numbers.txt," calculate


their sum, and print the result.

You might also like