0% found this document useful (0 votes)
2 views4 pages

Python Practical Notebook Final-1

The document contains a practical notebook for Python programming with 15 different programs. Each program has a specific aim, code implementation, and example output demonstrating its functionality. Topics covered include checking even/odd numbers, determining positivity, printing patterns, and calculating factorials, among others.

Uploaded by

atharvamewade568
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)
2 views4 pages

Python Practical Notebook Final-1

The document contains a practical notebook for Python programming with 15 different programs. Each program has a specific aim, code implementation, and example output demonstrating its functionality. Topics covered include checking even/odd numbers, determining positivity, printing patterns, and calculating factorials, among others.

Uploaded by

atharvamewade568
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

PYTHON PRACTICAL NOTEBOOK

Subject: Python Programming

Program 1
Aim: To check whether a number is Even or Odd.
Program:
num = int(input("Enter a number: "))

if num % 2 == 0:
print("Even Number")
else:
print("Odd Number")

Output:
Enter a number: 9
Odd Number

Program 2
Aim: To check whether a number is Positive, Negative or Zero.
Program:
num = int(input("Enter a number: "))

if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")

Output:
Enter a number: -5
Negative

Program 3
Aim: To print numbers from 1 to 10.
Program:
for i in range(1, 11):
print(i)

Output:
1
2
3
4
5
6
7
8
9
10

Program 4
Aim: To find square of a number.
Program:
num = int(input("Enter a number: "))
print("Square =", num * num)
Output:
Enter a number: 6
Square = 36

Program 5
Aim: To check voting eligibility.
Program:
age = int(input("Enter age: "))

if age >= 18:


print("Eligible for Voting")
else:
print("Not Eligible for Voting")

Output:
Enter age: 16
Not Eligible for Voting

Program 6
Aim: To print table of a number.
Program:
num = int(input("Enter number: "))

for i in range(1, 11):


print(num, "x", i, "=", num*i)

Output:
Enter number: 5
5 x 1 = 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

Program 7
Aim: To find sum of first N natural numbers.
Program:
n = int(input("Enter n: "))
total = 0

for i in range(1, n+1):


total += i

print("Sum =", total)

Output:
Enter n: 5
Sum = 15

Program 8
Aim: To find factorial of a number.
Program:
n = int(input("Enter number: "))
fact = 1

for i in range(1, n+1):


fact = fact * i

print("Factorial =", fact)


Output:
Enter number: 5
Factorial = 120

Program 9
Aim: To find largest among three numbers.
Program:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a > b and a > c:


print("Largest =", a)
elif b > c:
print("Largest =", b)
else:
print("Largest =", c)

Output:
Enter first number: 10
Enter second number: 25
Enter third number: 15
Largest = 25

Program 10
Aim: To count even numbers between 1 to N.
Program:
n = int(input("Enter n: "))
count = 0

for i in range(1, n+1):


if i % 2 == 0:
count += 1

print("Total Even Numbers =", count)

Output:
Enter n: 10
Total Even Numbers = 5

Program 11
Aim: To check whether a number is Prime or not.
Program:
num = int(input("Enter number: "))
flag = 0

for i in range(2, num):


if num % i == 0:
flag = 1
break

if num > 1 and flag == 0:


print("Prime Number")
else:
print("Not Prime")

Output:
Enter number: 7
Prime Number

Program 12
Aim: To reverse a number.
Program:
num = int(input("Enter number: "))
rev = 0

while num > 0:


rev = rev * 10 + num % 10
num //= 10

print("Reverse =", rev)

Output:
Enter number: 123
Reverse = 321

Program 13
Aim: To check whether a number is Palindrome or not.
Program:
num = int(input("Enter number: "))
temp = num
rev = 0

while num > 0:


rev = rev * 10 + num % 10
num //= 10

if rev == temp:
print("Palindrome Number")
else:
print("Not Palindrome")

Output:
Enter number: 121
Palindrome Number

Program 14
Aim: To print star pattern.
Program:
n = int(input("Enter rows: "))

for i in range(1, n+1):


for j in range(i):
print("*", end=" ")
print()

Output:
Enter rows: 4
*
* *
* * *
* * * *

Program 15
Aim: To print number pattern.
Program:
n = int(input("Enter rows: "))

for i in range(1, n+1):


for j in range(1, i+1):
print(j, end=" ")
print()

Output:
Enter rows: 4
1
1 2
1 2 3
1 2 3 4

You might also like