INFORMATICS PRACTICES
Presented to:
Shahzad Sir
Made by:
ABDUL RAFAY XIC
ACKNOWLEDGEMENT
I would like to express my special thanks
to my teacher MR. SHAHZAD ALI who
gave me such an opportunity to complete
this practical file. He has been a source of
inspiration and helped me to understand
and remember important details of
practical file. My practical file has been
success only because of his guidance.
CERTIFICATE
This is certify this Informatics Practices
PRACTICAL FILE is prepared by
___________
ABDUL RAFAY for the partial fulfilment
Term end Examination 2023-24).
Mr. SHAHZAD ALI (IP TEACHER)
15 PYTHON PROGRAMS
BY ABDUL RAFAY
PROGRAM 1 : Hello World
print("Hello, World!")
Output: Hello, World!
PROGRAM 2 : ADDITION OF TWO NUMBERS
num 1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum = num1 + num2
print("Sum:", sum)
Output:
Enter first number: 5
Enter second number: 7
Sum: 12
PROGRAM 3 : Area Of Rectangle
length = float(input("Enter length: "))
width = float(input("Enter width: "))
area = length * width
print("Area of the rectangle:", area)
Output:
Enter length: 4.5
Enter width: 3
Area of the rectangle: 13.5
New Section 1 Page 1
PROGRAM 4: Simple Interest Calculation
principal = float(input("Enter principal amount: "))
rate = float(input("Enter rate of interest: "))
time = float(input("Enter time (in years): "))
simple_interest = (principal * rate * time) / 100
print("Simple Interest:", simple_interest)
Output:
Enter principal amount: 1000
Enter rate of interest: 5
Enter time (in years): 2
Simple Interest: 100.0
PROGRAM 5: Celsius To Fahrenheit conversion
celsius = int(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
Output:
Enter temperature in Celsius: 25
Temperature in Fahrenheit: 77.0
PROGRAM 6: Check whether a number is even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Output:
Enter a number: 9
Odd
New Section 1 Page 2
PROGRAM 7: Print Numbers from 1to 5
for i in range (1, 6):
print(i)
Output :
1
2
3
4
5
PROGRAM 8 : Print multiples of 3up to 10
for i in range (3, 11, 3):
print(i)
Output : 3
6
9
PROGRAM 9: Print a Pattern
rows = 5
for i in range (1, rows + 1):
for j in range (1, i + 1):
print(j, end=" ")
print()
Output : 1
12
123
1234
12345
New Section 1 Page 3
PROGRAM 10: Right Triangle Star Pattern
rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print("*", end=" ")
print()
Output : *
**
***
****
*****
PROGRAM 11 : Sum Of elements in a list
numbers = [1, 2, 3, 4, 5]
Sum of elements = sum(numbers)
print("Sum of elements:", Sum of elements)
Output :
Sum of elements: 15
PROGRAM 12 : Sum Of elements in a list
numbers = [8, 3, 1, 6, 7, 2]
max_number = max(numbers)
min_number = min(numbers)
print("Maximum:", max_number)
print("Minimum:", min_number)
Output : Minimum: 1
Maximum: 8
New Section 1 Page 4
PROGRAM 13 : Creating a Dictionary and accessing it
# Creating a dictionary
student = {'name': 'John', 'age': 20, 'grade': 'A'}
# Accessing values
print("Name:", student['name'])
print("Age:", student['age'])
print("Grade:", student['grade'])
Output : Name: John
Age: 20
Grade: A
PROGRAM 14 : Creating a Dictionary and accessing it
student = {'name': 'John', 'age': 20, 'grade': 'A'}
Lenth of dictionary = len(student)
print("length of dictionary is", Length of dictionary)
Output : length of dictionary is 4
PROGRAM 15 : Thank You
print('Thank YOU ')
Output : Thank YOU
New Section 1 Page 5