Kle Ipc Lab Manual Pu 1
Kle Ipc Lab Manual Pu 1
OUTPUT:
Enter an Integer: 10
Enter an another Integer: 50
Numbers before swapping
a = 10 b = 50
2. Numbers after swapping
a = 50 b = 10
2) Write a python program to enter two integers and perform all
arithmetic operations on them.
OUTPUT:
Enter first number: 10
Enter second number: 4
Printing the result for all arithmetic operations:-
Addition: 14
Subtraction: 6
Multiplication: 4 0
Division: 2.5
Modulus: 2
3) Write a Python program to accept length and width of a
rectangle and compute its perimeter and area.
Output:
Enter length of the rectangle: 6
Enter breadth of the rectangle: 10
Area of rectangle = 60.0
Perimeter of rectangle = 32.0
4) Write a Python program to calculate the amount payable if money has
been lent on simple interest.
Principal or money lent = P
Rate of interest = R% per annum
Time = T years
Then Simple Interest (SI) = (P x R x T)/ 100
Amount payable = Principal + SI.
P, R and T are given as input to the program.
Output:
Enter amount: 1500
Enter time: 10
Enter rate: 2.5
Simple interest is: 375.0
Amount payable is: 1875.0
5) Write a Python program to find largest among three numbers.
Output:
Enter first number: 23
Enter second number: 36
Enter third number: 93
The largest number is 93.0
6) Write a program that takes the name and age of the user as input
and displays a message whether the user is eligible to apply for a
driving license or not. (The eligible age is 18 years).
Output:
What is your name? Anil
What is your age? 14
You are not eligible to apply for the driving license.
7) Write a program that prints minimum and maximum of five numbers
entered by the user.
START
Count=0
NO
Count < 5
YES
Output : large,small
INPUT: n
NO
count == 0 STOP
YES
Small = large = n
NO
n < small
YES
count=count+1 Small = n
YES
NO
n > large
large = n
largest=smallest=0
for count in range(0,5):
n = int(input("Enter the number: ")) Output:
if count == 0: Enter the number: 22
smallest = largest = n Enter the number: 96
if(n < smallest): Enter the number: 21
smallest = n Enter the number: 3
Enter the number: 5
if(n > largest):
The smallest number is 3
largest = n
The largest number is 96
print("The smallest number is ",smallest)
print("The largest number is ",largest)
8) Write a python program to find the grade of a student when grades are
allocated as given in the table below.
Percentage of Marks Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
Percentage of the marks obtained by the student is input to the program.
Output:
Enter the number: 657
The sum of digits of the number is 18
11) Write a program to check whether an input number is a palindrome or
not.
(A palindrome number is a number that reads the same forward and backward.)
n = int(input("Enter a number:"))
temp = n
reverse = 0
while(n>0):
digit = n % 10
reverse = reverse*10 + digit
n = n // 10 Output:
if(temp == reverse): Enter a number: 16461
print("Palindrome") Palindrome
else:
print("Not a Palindrome")
12) Write a python program to print the following patterns:
12345
1234
123
12
1
START
Rows=5
i=rows
NO
i>0
YES
j=1 END
i=i-1
print () j >= i
NO
YES
print ( j, end=” “)
j += 1
rows = 5
for i in range(rows,0,-1):
for j in range(1, i+1):
print(j, end=" ")
print()
Output:
12345
1234
123
12
1
13) Write a program that uses a user defined function that accepts name
and gender (as M for Male, F for Female) and prefixes Mr/Ms on the basis
of the gender.
def prefix(name,gender):
if (gender == 'M' or gender == 'm'):
print("Hello, Mr.",name)
elif (gender == 'F' or gender == 'f'):
print("Hello, Ms.",name)
else:
print("Please enter only M or F in gender")
Output :
Enter the co-efficients of quadratic equation
Enter the value of a: 5
Enter the value of b: 3
Enter the value of c: 6
Output :
Enter Number 1: 65
Enter Number 2: 95
Entered values are :
Number 1: 65 Number 2: 95
values after swap function:
Number 1: 95 Number 2: 65
16) Write a python program to input line(s) of text from the user until enter
is pressed. Count the total number of characters in the text (including white
spaces), total number of alphabets, total number of digits, total number of
special symbols and total number of words in the given text. (Assume that
each word is separated by one space).
Output :
Write a sentence: The class is at 9 am on 16/12/24.
Total Characters: 33
Total Alphabets: 16
Total Digits: 7
Total Special Characters: 10
Total Words in the Input : 8
17) Write a user defined function to convert a string with more than one
word into title case string where string is passed as parameter.
(Title case means that the first letter of each word is capitalised)
def convert(str):
if “ “ in str:
b=str.split(“ “)
if len(b)>1:
print("The input string in title case is:", str.title())
else:
print("The String is of one word only")
text = input("Write a sentence more than one word : ")
convert(text)
Output:
Write a sentence: hai how are you
The input string in title case is: Hai How Are You
def replaceChar(string):
return string.replace(' ','-')
userInput = input("Enter a sentence: ")
result = replaceChar(userInput)
print("The new sentence is:",result)
Output:
Output :
enter the elements seperated by commas :12,24,12,45,12,56
The list is: [12, 24, 12, 45, 12, 56]
Which element occurrence would you like to count? 12
The count of element 12 in the list is: 3
20) Write a python function that returns the largest element of the list passed
as parameter.
def largest(list1):
large=max(list1)
return large
Output:
enter the elements separated by commas :1,2,3,4,5,6
The elements of the list [1, 2, 3, 4, 5, 6]
The largest number of the list: 6
21) Write a python program to read a list of elements. Modify this list so that
it does not contain any duplicate elements, i.e., all elements occurring
multiple times in the list should appear only once.
Output:
enter the elements separated by commas :10,20,30,10,20
The list entered is: [10, 20, 30, 10, 20]
List without duplicate element is: [10, 20, 30]
22) Write a python program to read email IDs of ‘n’ number of
students and store them in a tuple. Create two new tuples, one to
store only the usernames from the email IDs and second to store
domain names from the email IDs. Print all three tuples at the end
of the program. [Hint: You may use the function split()]
emails = tuple()
username = tuple()
domainname = tuple()
n = int(input("Enter number of students : "))
for i in range(0,n):
emid = input("Enter email ID for student {i+1}> ")
emails = emails + (emid,)
spl = emid.split("@")
username = username + (spl[0],)
domainname = domainname + (spl[1],)
print("\nThe email id’s in the tuple are:")
print(emails)
print("\nThe username in the email id’s are:")
print(username)
print("\nThe domain name in the email id’s are:")
print(domainname)
std_names = tuple()
n = int(input("Enter number of students: "))