0% found this document useful (0 votes)
7 views13 pages

PythonLabProgram IX

The document outlines a series of Python lab programs aimed at teaching basic programming concepts such as printing, arithmetic operations, conditionals, loops, and data structures. Each lab includes a specific aim, program code, and example outputs demonstrating the functionality of the code. The programs cover a variety of topics including personal information display, energy calculation, distance calculation, and checking for odd/even numbers, among others.

Uploaded by

vsneha2514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

PythonLabProgram IX

The document outlines a series of Python lab programs aimed at teaching basic programming concepts such as printing, arithmetic operations, conditionals, loops, and data structures. Each lab includes a specific aim, program code, and example outputs demonstrating the functionality of the code. The programs cover a variety of topics including personal information display, energy calculation, distance calculation, and checking for odd/even numbers, among others.

Uploaded by

vsneha2514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

(Right side Page)

Lab Program 1:
Write a python program to print 5 lines about yourself using print() function
Aim:
To print 5 lines about yourself using print( ) function in Python.
Program:
a = input(“Enter your name: ”)
b=input(“Enter your class: ” )
c=int(input(“Enter your Age: ”))
d=input(“Enter your school name: ”)
e=input(“Enter your hobbies: ”)
print(“My name is: ”, a)
print(“My Class is: ”, b)
print(“My Age is : ”, c)
print(“My School name is: ”, d)
print(“My Hobbies are: ”, e)
Result:
Thus, we printed 5 lines about ourself using print( ) function.
(Left side Page)
Write a python program to print 5 lines about yourself using print() function

Output
Enter your name: vimna
Enter your class: IX B
Enter your age: 13
Enter your school name: KV CLRI
Enter your hobbies: Reading
My name is: vimna
My class is: IX B
My age is: 13
My school name is: KV CLRI
My hobbies are: Reading

Lab Program: 2
Write a program to calculate energy using this formula: energy = mgh
Aim:
To calculate energy using the Arithmetic operators in python.
Program:
g=9.8
m=float(input(“Enter the value of m: ”))
h=float(input(“Enter the value of h: ”))
energy = m*g*h
print(“Energy = ”,energy)
Result:
Thus Energy value has been calculated using arithmetic operators.

(leftside)
Write a program to calculate energy using this formula: energy = mgh
output
Enter the value of m: 22
Enter the value of h: 11
Energy = 2371.6000000000004

Lab Program : 3
Q: Write a program to calculate distance using the given formula distance = ut+1/2 at2.
Aim:
To create a python program to calculate the distance using Arithmetic Operators
Program:
u=float(input(“Enter the value of u: ”))
t=float(input(“Enter the value of t: ”))
a=float(input(“Enter the value of a: ”))
distance = u*t + 0.5 *a*(t**2)
print(“Distance = ”,distance)
Result:
Thus the distance value is calculated using Arithmetic operators in Python.

(Leftside)
Write a program to calculate distance using the given formula distance = ut+1/2 at2

Output

Enter the value of u: 13


Enter the value of t: 12
Enter the value of a: 2
Distance = 300.0
Lab Program: 4
Q: Write a program to demonstrate the use of floor division (//) and modulo operator(%) in
python.
Aim:
To demonstrate the use of floor division and modulo operator in python.
Program:
a= int(input(“Enter the value of a: “))
b= int(input(“Enter the value of b: ”))
c= a//b
Print(“The floor division of A and B is: ”, c)
d=a%b
print(“The modulus of A and B is: ”,d)
Result:
Thus the python program is done using floor division and modulo operator.

(Leftside)
Write a program to demonstrate the use of floor division (//) and modulo operator(%) in
python.

output
Enter the value of a: 10
Enter the value of b: 2
The floor division of A and B is: 5
The modulus of A and B is: 0

Lab Program: 5
Q: Write a program to lock or unlock your phone using pin or password and generate
appropriate message.
Aim:
To create a program to lock or unlock the phone using pin or password
Program:
pwd=input(“Enter the password: ”)
if pwd=”Welcome”:
print(“Phone is Unlocked Successfully”)
else:
print(“Incorrect Password”)
Result :
Thus using if-else statement python program is created.
(Left side)
Write a program to lock or unlock your phone using pin or password and generate appropriate
message.
Output
Enter the password: Welcome
Phone is Unlocked Successfully
Lab program: 6
Q: Write a program to check whether the entered number is odd or even.
Aim:
To create a python program to check the entered number is odd or even using if-else
statement
Program
a=int(input(“Enter the number: ”)
if a%2==0:
print(a, “is an even number”)
else:
print(a, ”is odd number”)
Result:
Thus the program is created using if-else statement to check the entered number is even or
odd.
(leftside)
Write a program to check whether the entered number is odd or even.

Output
Enter the number: 5
5 is an odd number

Lab Program 7
Q: A tours and travels company charges their customer as per following criteria according
to customer category:
Category Charges
A 18
B 15
C 12
D 10

Aim: To create a python program using if-elif-else.

Program:
c_type= input("Enter the customer type for A to D:")
distance=int(input("Enter the distance: "))
if c_type=='A':
ch=18
elif c_type=='B':
ch=15
elif c_type=='C':
ch=12
elif c_type=='D':
ch=10
else:
ch=20
fare=distance*ch
print("Total Amount = ",fare)

Result: Thus the program was created using if-elif-else.

(leftside)
Output
Enter the customer type for A to D: D
Enter the distance: 100
Total Amount = 1000
Lab program: 8
Q: Write a program to implement an increment to the employees based on their appraisal
score given in the following table:

Appraisal Score Rate of Increment

0-10 3%

11-30 5%

31-50 8%

51-80 10%
81-100 15%
Aim: To create a python program using if-elif-else.

Program:
app_score = int(input("Enter the Appraisal Score between 0-100: "))
sal_amount=float(input("Enter the salary: "))
if app_score>=0 and app_score<=10:
inc=0.03
elif app_score>10 and app_score<=30:
inc=0.05
elif app_score>30 and app_score<=50:
inc=0.08
elif app_score>50 and app_score<=80:
inc=0.10
elif app_score>80 and app_score<=100:
inc=0.15
else:
print("Invalid Appraisal Score")
sal_amount+=(sal_amount*inc)
print("Salary = ",sal_amount)
Result:
Thus the program was created using if-elif-else statement.
(Leftside)
Output
Enter the Appraisal Score between 0-100: 20
Enter the salary: 50000
Salary = 52500.0
Lab program: 9
Q: Write a program to reverse entered number using while loop.

Aim: To create a python program to reverse the number.

Program:
Number = int(input("Please Enter any Number: "))
Reverse = 0
while(Number > 0):
Reminder = Number %10
Reverse = (Reverse *10) + Reminder
Number = Number //10

print("\n Reverse of entered number is = " ,Reverse)

Result:
Thus the program was created using while loop.

(Leftside)
Write a program to reverse entered number using while loop.
Output

Please Enter any Number: 267

Reverse of entered number is = 762


Lab program: 10

Q: Write a program to check entered number is Palindrome or not

Aim: to create a python program to check the entered number is palindrome or not.
Program:
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")

Result: Thus the program was created using while loop to check the entered number is
palindrome or not.
(leftside)
Write a program to check entered number is Palindrome or not
Output
Enter number: 424
The number is a palindrome!

Lab Program: 11

Q: Write a program to check entered number is Armstrong or not

Aim: To create a python program to check the entered number is Armstrong or not.

Program
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")

Result: Thus the program has been created to check the entered number is Armstrong or not.
(Leftside)
Write a program to check entered number is Armstrong or not

Output

Enter a number: 153


153 is an Armstrong number
Lab program : 12

Q: Write a program to print a multiplication table of entered number using for loop

Aim: To create a python program using for loop.

Program:
number = int(input ("Enter the number of which the user wants to print the multiplication table: "))
print ("The Multiplication Table of: ", number)
for count in range(1, 11):
print (number, 'x', count, '=', number * count)
Result: Thus the multiplication table program was created using for loop.
(Leftside)
Write a program to print a multiplication table of entered number using for loop

Output
Enter the number for which you want the multiplication table: 5
The Multiplication Table of: 5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Lab program: 13
Q: Write a program to find sum of first N numbers
To create a python program to find the sum of first N numbers using for loop.
Program:
sum = 0
print("Enter the Value of n: ")
n = int(input())
print("Enter " + str(n) + " Numbers: ")
for i in range(n):
num = int(input())
sum = sum+num
print("Sum of " + str(n) + " Numbers = " + str(sum))
Result:
Thus the Program was created to find the sum of first N numbers.
(leftside)
Output
Enter the value of n:
4
Enter 4 numbers:
10
20
30
10
Sum of 4 numbers = 70

Lab program: 14

Q: Write a program to find average of first N numbers using for loop

Aim: To create a python program to find the average of first N numbers

Program:
n = int(input("Enter number"))
sum = 0
for num in range(1, n + 1, 1):
sum = sum + num
print("Sum of first ", n, "numbers is: ", sum)
average = sum / n
print("Average of ", n, "numbers is: ", average)
Result:
Thus the Program was created to find the average of first N numbers.
(Leftside)
Write a program to find average of first N numbers using for loop

Output
Enter number: 3
Sum of first 3 numbers is: 6
Average of 3 numbers is: 2.0

Lab Program: 15
Q: Write a python program to create a list and display its elements

Aim: To create a list and display its elements

Program:

fruits = ["apple", "banana", "cherry", "mango"]


print("The list of fruits is:", fruits)
print("The fruits are:")
for i in fruits:
print(i)

Result:
Thus the List was created and its elements are displayed successfully.
(Leftside)
Write a python program to create a list and display its elements

Output
The list of fruits is: ['apple', 'banana', 'cherry', 'mango']
The fruits are:
apple
banana
cherry
mango

You might also like