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

python sample programs

The document outlines various Python programs with specific aims, procedures, and source codes for tasks such as finding the largest of three numbers, calculating simple interest, creating a student marksheet, determining leap years, and implementing inheritance. Each section includes a brief aim, step-by-step procedure, and the corresponding source code. The document serves as a guide for beginners to understand basic programming concepts in Python.

Uploaded by

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

python sample programs

The document outlines various Python programs with specific aims, procedures, and source codes for tasks such as finding the largest of three numbers, calculating simple interest, creating a student marksheet, determining leap years, and implementing inheritance. Each section includes a brief aim, step-by-step procedure, and the corresponding source code. The document serves as a guide for beginners to understand basic programming concepts in Python.

Uploaded by

riaz ahamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

4

1. Largest of Three Number.

AIM: To write python program to find largest of three number.

PROCEDURE:

 Open the python window.


 Type the code of largest of three number program.
 Save the program.
 Run the program.

SOURCE CODE:
a=(input("Enter a"))
b=(input("Enter b"))
c=(input("Enter c"))
if a>b and a>c:
print("a is largest")
if b>a and b>c:
print("b is Largest")
if c>a and c>b:
print("c is Largest")
5

OUTPUT:
6

2. Simple Interest Calculator

AIM: To Write python program to find Simple Interest Calculator

PROCEDURE:

 Open the python window.


 Type the code of Simple Interest Calulator program.
 Save the program.
 Run the program.

SOURCE CODE:
def simple_interest(p,r,t):
return(p*r*t)/100
p=float(input("Enter the principal amount?"))
r=float(input("Enter the rate of interest?"))
t=float(input("Enter the time in year?"))
print("Simple interest",simple_interest(p,r,t))
7

OUTPUT:
8

3. Students Marksheet

AIM: To Write python program to create a Students Marksheet.

PROCEDURE:

 Open the python window.


 Type the code of Simple Interest Calulator program.
 Save the program.
 Run the program.

SOURCE CODE:
marks=int(input("Enter the marks"))
if marks>85 and marks<=100:
print("Congrats ! you scored grade A...")
elif marks>60 and marks<=85:
print("You scored grade B++...")
elif marks>40 and marks<=60:
print("you scored grade B...")
elif marks>30 and marks<=40:
print("you scored grade c...")
else:
print("Sorry you are fail")
9

Output:
10

4. Leap Year

AIM: To Write python program to find Leap Year.

PROCEDURE:

 Open the python window.


 Type the code of Leap Year program.
 Save the program.
 Run the program.

SOURCE CODE:
year = int(input("Enter a year: "))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
11

Output:
12

5. Inside and Outside the Function.


AIM: To Write python program add the value Inside and Outside the Function.

PROCEDURE:

 Open the python window.


 Type the code add the value Inside and outside the function program.
 Save the program.
 Run the program.

SOURCE CODE:
def my_func():
x = 10
print("Value inside function:",x)

x = 20
my_func()
print("Value outside function:",x)
13

Output:
14

6.The Factorial Value to the given number.

AIM: To Write python program find the Factorial Value to the given number.

PROCEDURE:

 Open the python window.


 Type the code to find the Factorial Value to the given number program.
 Save the program.
 Run the program.

SOURCE CODE:
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))

num = 3
print("The factorial of", num, "is", factorial(num))
15

Output:
16

7. Arithmetic Operation on Numbers.

AIM: To Write python program to perform different arithmetic operation on


numbers.

PROCEDURE:

 Open the python window.


 Type the code to perform different arithmetic operation on numbers program.
 Save the program.
 Run the program.

SOURCE CODE:
num_1 = int(input('Enter your first number: '))
num_2 = int(input('Enter your second number: '))
print('{} + {} = '.format(num_1, num_2))
print(num_1 + num_2)
print('{} - {} = '.format(num_1, num_2))
print(num_1 - num_2)
print('{} * {} = '.format(num_1, num_2))
print(num_1 * num_2)
print('{} / {} = '.format(num_1, num_2))
print(num_1 / num_2)
17

Output:
18

8.The Different Between the Two Lists.

AIM: To Write python program to get the difference between the two lists.

PROCEDURE:

 Open the python window.


 Type the code to get the different between the two lists program.
 Save the program.
 Run the program.

SOURCE CODE:
list1 = [1, 3, 5, 7, 9]
list2=[1, 2, 4, 6, 7, 8]
diff_list1_list2 = list(set(list1) - set(list2))
diff_list2_list1 = list(set(list2) - set(list1))
total_diff = diff_list1_list2 + diff_list2_list1
print(total_diff)
19

Output:
20

9. Implement Inheritance.

AIM: To Write python program to Implement Inheritance.

PROCEDURE:

 Open the python window.


 Type the code to Implement Inheritance program.
 Save the program.
 Run the program.

SOURCE CODE:
class Family:
def show_family(self):
print("This is our family:")
class Father(Family):
fathername = ""
def show_father(self):
print(self.fathername)
class Mother(Family):
mothername = ""
def show_mother(self):
print(self.mothername)
class Son(Father, Mother):
def show_parent(self):
print("Father :", self.fathername)
print("Mother :", self.mothername)
21

s1 = Son()
s1.fathername = "Mark"
s1.mothername = "Sonia"
s1.show_family()
s1.show_parent()
22

Output:
23

10. Class and Object.

AIM: To Write python program using Class and Object.

PROCEDURE:

 Open the python window.


 Type the codeusing Class and Object program.
 Save the program.
 Run the program.

SOURCE CODE:
class Person:
"This is a person class"
age = 10

def greet(self):
print('Hello')

harry = Person()
print(Person.greet)
print(harry.greet)
harry.greet()
24

Output:

You might also like