0% found this document useful (0 votes)
5 views15 pages

Python Lab Final

This document contains a collection of Python programming exercises for a B.Sc. VI Semester course. Each exercise includes code snippets for various tasks such as addition of numbers, calculating the area of a triangle, finding averages, and handling exceptions. The document serves as a practical guide for students to learn and implement Python programming concepts.

Uploaded by

upendrareddy
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)
5 views15 pages

Python Lab Final

This document contains a collection of Python programming exercises for a B.Sc. VI Semester course. Each exercise includes code snippets for various tasks such as addition of numbers, calculating the area of a triangle, finding averages, and handling exceptions. The document serves as a practical guide for students to learn and implement Python programming concepts.

Uploaded by

upendrareddy
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

[Link].

- VI Semester

INDEX
Signature
Practical-VI(a):DSE 6: Python Programming
[Link] Page No. of the
Lab
Faculty

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

1
[Link].- VI Semester

01) #Python program for Addition of two numbers

Number1=input("Enter first Number:")

Number2=input("Enter second Number:")

sum=float(Number1)+float(Number2)

print("The sum of {0} and {1} is {2}".format(Number1,Number2,sum))

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

Enter first Number:10

Enter second Number:-1

The sum of 10 and -1 is 9.0

===================== RESTART: C:\Users\admin\[Link] ====================

Enter first Number:25

Enter second Number:08

The sum of 25 and 08 is 33.0

2
[Link].- VI Semester

02) # Python program to find the area of a triangle whose sides are given.

import math

a=float(input("enter the length of side a:"))

b=float(input("enter the length of side b:"))

c=float(input("enter the length of side c:"))

s=(a+b+c)/2

area=[Link](s*(s-a)*(s-b)*(s-c))

print ("area of the triangle is:",area)

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

enter the length of side a:8

enter the length of side b:6

enter the length of side c:4

area of the triangle is: 11.61895003862225

3
[Link].- VI Semester

03) # Python program to find out the average of a set of integers.

count=int(input("enter the count of number:"))

i=0

sum=0

for i in range(count):

x=int(input("enter an integer:"))

sum=sum+x

avg=sum/count

print("the average is:",avg)

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

enter the count of number:5

enter an integer:3

the average is: 0.6

enter an integer:8

the average is: 2.2

enter an integer:6

the average is: 3.4

enter an integer:7

the average is: 4.8

enter an integer:4

the average is: 5.6

4
[Link].- VI Semester

04) # Python program to check whether the given number is even or not.

number=input("Enter a number")

x=int(number)%2

if x==0:

print("The number is even")

else:

print("The number is odd")

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

Enter a number8

The number is even

5
[Link].- VI Semester

05) # Python program to find the product of a set of real numbers.

i=0

product=1

count=int(input("Enter the number of real numbers:"))

for i in range(count):

x=float(input("Enter a real number:"))

product=product*x

print("The product of the numbers is:",product)

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

Enter the number of real numbers:1

Enter a real number:2

The product of the numbers is: 2.0

6
[Link].- VI Semester

06) # Python program to find simple interest of a given values.

def simpleinterest(P,T,R):

SI=(P*T*R)/100

return SI

P=int(input("enter the principal amount:"))

T=int(input("enter the principal time:"))

R=float(input("enter the principal rate of interest:"))

print(simpleinterest(P,T,R))

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

enter the principal amount:100000

enter the principal time:12

enter the principal rate of interest:3

36000.0

7
[Link].- VI Semester

07) # Python program to convert the temperature in degree centigrade to Fahrenheit.

c=input("Enter temperature in centigrade:")

f=(9*(int(c))/5)+32

print("temperature in fahrenheitis:",f)

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

Enter temperature in centigrade:30

temperature in fahrenheit is: 86.0

8
[Link].- VI Semester

08) # Python program to generate a list by inputting the values.

n=int(input("Enter the size of list :"))

lst=list(map(int,input("Enter the integer\elements:").strip().split()))[:n]

print('The list is :',lst)

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

Enter the size of list :6

Enter the integer\elements:423561

The list is : [423561]

9
[Link].- VI Semester

09) # Python program to create different types of tuples.

my_tuple=()

print(my_tuple)

my_tuple=(1,2,3)

print(my_tuple)

my_tuple=(1,"Hello",3.4)

print(my_tuple)

my_tuple=("mouse",[8,4,6],[1,2,3])

print(my_tuple)

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

()

(1, 2, 3)

(1, 'Hello', 3.4)

('mouse', [8, 4, 6], [1, 2, 3])

10
[Link].- VI Semester

10) # Python program for changing and adding dictionary elements.

my_dict={'name':'jack','age':26}

my_dict['age']=27

print(my_dict)

my_dict['address']:'Downtown'

print(my_dict)

===================== RESTART: C:\Users\admin\[Link] ====================

OUTPUT:

{'name': 'jack', 'age': 27}

{'name': 'jack', 'age': 27}

11
[Link].- VI Semester

11) # Python program on File handling()

f1=open("[Link]","w")

[Link]("Welcome to Python Programming")

[Link]()

f1=open("[Link]","r")

print([Link](30))

[Link]()

==================== RESTART: C:\Users\admin\[Link] ===================

OUTPUT:

Welcome to Python Programming

12
[Link].- VI Semester

12) # Python program on exception handling


try:

print('try block')

X=int(input('enter a number:'))

Y=int(input('enter another number:'))

Z=X/Y

except ZeroDivisionError:

print("except ZeroDivisionError block")

print("Division by 0 not accepted")

else:

print("else block")

print ("division=",Z)

finally:

print("finally block")

X=0

Y=0

print("Out of try,except,else and finally blocks.")

===================== RESTART: C:\Users\admin\[Link] ====================


OUTPUT:

try block

enter a number:10

enter another number:2

else block

division= 5.0

finally block

Out of try,except,else and finally blocks.

OUTPUT:

try block

enter a number:10

enter another number:0

except ZeroDivisionError block

Division by 0 not accepted

finally block

Out of try,except,else and finally blocks.

13
[Link].- VI Semester

13) #Python program on single inheritance

class Employee:

defgetEmployeeInfo(self):

self._id=input("Enter Employee Id:")

self._name=input("Enter Name:")

self._salary=int(input("Enter Employee Salary:"))

defprintEmployeeInfo(self):

print("ID:",self._id,",name:",self._name,",BasicSalary:",self._salary)

defgetSalary(self):

return(self._salary)

class Perks(Employee):

defgetPerks(self):

[Link]()

sal=[Link]()

self._da=sal*35/100

self._hra=sal*17/100

defprintPerks(self):

[Link]()

print("Total Salary",([Link]()+self._da+self._hra))

S=Perks()

[Link]()

print("Employee information")

[Link]()

======================= RESTART: C:\Users\admin\[Link] =======================

Enter Employee Id:12345

Enter Name:Adesh

Enter Employee Salary:50000

Employee information

ID: 12345 ,name: Adesh ,Basic Salary: 50000

Total Salary 76000.0

14
[Link].- VI Semester

14) # Python program on GUI programming

import TKinter as tk

Window=[Link]()

[Link]("GUI")

[Link](window,text="username").grid(row=0)

[Link](window).grid(row=0,column=1)

[Link](window,text="password").grid(row=1)

[Link](window).grid(row=1,column=1)

[Link](window,text="Keep me loggedin").grid(columnspan=2)

[Link]()

===================== RESTART: C:\Users\admin\[Link] ====================

15

You might also like