Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views

Python Programs For Practical Notebook PDF

The document contains Python code examples for basic mathematical and logical operations, including printing text, calculating sums, multiplications, areas of shapes, distance conversions, and determining largest/smallest values. The code samples demonstrate fundamentals like accepting user input, performing calculations, and printing output.

Uploaded by

COMPUTER LAB
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Python Programs For Practical Notebook PDF

The document contains Python code examples for basic mathematical and logical operations, including printing text, calculating sums, multiplications, areas of shapes, distance conversions, and determining largest/smallest values. The code samples demonstrate fundamentals like accepting user input, performing calculations, and printing output.

Uploaded by

COMPUTER LAB
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#Program to type Hello World

print('Hello, World!')

Output
Hello, World!

_____________________________________

#sum of two numbers

number1 = input('Enter first number: ')


number2 = input('Enter second number: ')

number1 = float(number1)
number2 = float(number2)

result = number1 + number2

print('Sumof %0.2f and %0.2f is %0.2f' % (number1,


number2, result))

Output

Enter first number: 12.23


Enter second number: 23.45
Sum of 12.23 and 23.45 is 35.68

Output

Enter first number: 12.23


Enter second number: 23.45
Sum of 12.23 and 23.45 is 35.68
# multiply two numbers

number1 = input('Enter first number: ')


number2 = input('Enter second number: ')

number1 = float(number1)
number2 = float(number2)

result = number1 * number2

print('%0.2f * %0.2f = %0.2f' % (number1, number2,


result))

Output

Enter first number: 12.23


Enter second number: 22.3
12.23 * 22.30 = 272.73

# Area & Perimeter of Rectangle

length = float(input("Enter length of the rectangle:


"))
breadth = float(input("Enter breadth of the rectangle:
"))

area = length * breadth

perimeter = 2 * (length * breadth)

print("Area of rectangle = ", area)


print("Perimeter of rectangle = ", perimeter)

Output
Enter length of the rectangle: 23
Enter breadth of the rectangle: 17
Area of rectangle = 391.0
Perimeter of rectangle = 782.0

___________________________________________________

# Finding area and circumference

# importing math module for PI


import math

radius = float(input('Enter radius of circle: '))

area = math.pi * radius ** 2


circumference = 2 * math.pi * radius

print('Area = %0.4f.' % (area))


print('Circumference = %0.4f.' % (circumference))

Output
Enter radius of circle: 5
Area = 78.5398.
Circumference = 31.4159.

# Area of triangle

base = float(input('Enter base: '))


height = float(input('Enter height: '))

area_triangle = base*height/2

print('Area of triangle is %f' %(area_triangle))

Output
Enter base: 23
Enter height: 32
Area of triangle is 368.000000

# Python program to convert km to m

km = input("Enter distance in kilometer: ")


km = float(km)
m = km * 1000;
print("%0.3f Kilometer = %0.3f Meter" %(km,m))

The output of the above program is:

Enter distance in kilometer: 5.436


5.436 Kilometer = 5436.000 Meter

# Python program to check leap year


year = int(input('Enter year: '))
if (year%4==0):
print('LEAP YEAR')
else:
print('NOT LEAP YEAR')

Output

Run 1:
------------------
Enter year: 2019
NOT LEAP YEAR

Run 2:
------------------
Enter year: 2024
LEAP YEAR
# Finding smallest of two numbers
first = float(input('Enter first number: '))
second = float(input('Enter second number: '))

if first < second:


small = first
else:
small = second

print('Smallest = %d' %(small))

Output
Run 1:
------------------
Enter first number: 33
Enter second number: 23
Smallest = 23

Run 2:
------------------
Enter first number: -45
Enter second number: 0
Smallest = -45

# Finding largest of three numbers


first = float(input('Enter first number: '))
second = float(input('Enter second number: '))
third = float(input('Enter third number: '))

if first >= second and first>=third:


large = first
elif second >= first and second >= third:
large = second
else:
large = third

print('Largest = %d' %(large))

Output
Run 1:
------------------
Enter first number: 32
Enter second number: 33
Enter third number: 45
Largest = 45

Run 2:
------------------
Enter first number: -8
Enter second number: 23
Enter third number: 12
Largest = 23

_______________________________________

You might also like