Program 1 a): Use a web browser to go to the Python website [Link]
This page contains information about
Python and links to Python- related pages, and it gives you the ability to search the Python documentation.
How to visit [Link] — Step-by-step (with diagrams)
Goal: Open the official Python website, find documentation, and use the search on the docs page.
Tools you'll need: A web browser (Chrome, Edge, Firefox, Safari) and an internet connection.
1. Open your web browser
+---------------------------------------------------------+
| [Tabs] 🔍 Address bar (URL) |
| [Link] |
+---------------------------------------------------------+
What to do: Double-click your browser icon to open it.
Diagram note: The long horizontal box above represents the browser window; the address bar is where you type URLs.
2. Click the address bar and type the URL
[Browser Address Bar]
┌──────────────────────────────────────────────┐
| [Link] |
└──────────────────────────────────────────────┘
↓ press **Enter** (or Return)
What to do: Click once in the address bar, type [Link] (or [Link] and press Enter.
Tip: Typing just [Link] usually works too.
3. The Python homepage (overview)
+------------------------------------------------------------+
| PYTHON logo | Menu: Downloads | Docs | Community | PSF |
+------------------------------------------------------------+
| [Hero area: Latest Python release & Download button] |
| [News and Events] |
| [Quick links: Docs, About, Success Stories, Jobs] |
+------------------------------------------------------------+
Important areas:
Downloads — to download installers for Windows/macOS/Linux
Docs — official documentation for tutorials, library references
Search (usually at top-right or within Docs) — type topics like list comprehension
4. Use the top menu: open Docs
Top Menu: [Downloads] [Docs] [Community]
↑ click **Docs**
What you'll see on the Docs page:
A search box to look up documentation topics
Links to: Tutorial, Library Reference, Language Reference, FAQs, What’s New
5. Search the docs (example: find list comprehension)
[Docs page]
┌─────────────────────────────────────────┐
| Search docs: [ list comprehension ▾ ] |
└─────────────────────────────────────────┘
↓ press Enter
Search results:
- Tutorial → Lists and list comprehensions
- Library ref → builtins related pages
What to do: Type a concise keyword or phrase and press Enter. Click the most relevant result.
6. Open a documentation page and navigate the sidebar
+---------------------------------------------+
| Page title: Lists — Python Tutorial |
+---------------------------------------------+
| Sidebar: |
| • Welcome |
| • Tutorial |
| - Using the Python Interpreter |
| - **Data Structures** (click this) |
| - More topics... |
+---------------------------------------------+
Use the sidebar to jump between sections. Use your browser’s Back button to return to previous pages.
7. Download Python (if you want to install)
[Homepage]
[Downloads] → Click your platform (e.g., Windows)
→ Click big yellow/blue button: "Download Python 3.x.y"
Steps:
1. Click Downloads → choose OS (Windows/macOS/Linux)
2. Click the prominent Download button
3. Run the downloaded installer and follow on-screen instructions (on Windows: check "Add Python to PATH"
before installing)
8. Quick keyboard shortcuts & tips
Ctrl+L or Alt+D — focus address bar (Windows/Linux). On macOS: Cmd+L.
Ctrl+F — find on page.
Use concise search terms in the docs (e.g., open(), for loop, list methods).
9. Troubleshooting
Site won’t load: check internet, try [Link] instead.
Confusing results: try the exact module name (e.g., json), or use Google with site:[Link] json.
Program 1 b) Write a python program to print “Hello World!” on the screen
Aim:- Write a Python program to print Hello-World Program:-
#To print Hello-world
>>>print(“Hello-World”)
Output :- Hello-World
Program 1 c) Write a Python program to find sum of two numbers.
Aim :-Write a Python program to add two-numbers
Program:-
>>>a=5
>>>b=10
>>>c=a+b
>>>print(c)
Output:- 15
Or
Program:-
h=int(input(“Enter a:”))
s=int(input(“Enter b:”))
c=h+s
print(c)
Output:-
Enter a:10
Enter b:15
25
Program 2 a): Start a Python interpreter and use it as a Calculator.
AIM
To start the Python interpreter and perform basic arithmetic operations such as addition, subtraction, multiplication, division, and modulus,
just like a calculator.
. ALGORITHM
1. Start the program.
2. Display options for arithmetic operations.
3. Read two numbers from the user.
4. Read the operator (+, –, *, /, %).
5. If operator is ‘+’, perform addition.
6. If operator is ‘–’, perform subtraction.
7. If operator is ‘*’, perform multiplication.
8. If operator is ‘/’, perform division.
9. If operator is ‘%’, perform modulus.
10. Display the result.
11. Stop the program.
FLOWCHART
┌──────────────┐
│ Start │
└───────┬──────┘
│
┌──────────▼───────────┐
│ Read number1 │
└──────────┬───────────┘
│
┌──────────▼───────────┐
│ Read number2 │
└──────────┬───────────┘
│
┌──────────▼───────────┐
│ Read operator (+-*/%)│
└──────────┬───────────┘
│
┌────────────▼─────────────┐
│ Check operator and │
│ perform calculation │
└────────────┬─────────────┘
│
┌───────────▼─────────────┐
│ Display result │
└───────────┬─────────────┘
│
┌──────▼──────┐
│ Stop │
└──────────────┘
PYTHON PROGRAM (Calculator using Interpreter)
# Simple Calculator in Python
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
op = input("Enter operator (+, -, *, /, %): ")
if op == '+':
result = num1 + num2
elif op == '-':
result = num1 - num2
elif op == '*':
result = num1 * num2
elif op == '/':
result = num1 / num2
elif op == '%':
result = num1 % num2
else:
result = "Invalid operator"
print("Result:", result)
SAMPLE INPUT
Enter first number: 10
Enter second number: 5
Enter operator (+, -, *, /, %): *
OUTPUT
Result: 50.0
Program 2 b) Python Program to Find the Square Root of a Number
Aim:
To write a Python program to find the square root of a given number.
Algorithm:
1. Start
2. Read a number from the user
3. Find the square root using the formula
→ √num = num ** 0.5
4. Display the result
5. Stop
Flowchart:
┌────────────┐
│ Start │
└────┬───────┘
↓
┌────────────────────┐
│ Input number (num) │
└────────────────────┘
↓
┌────────────────────┐
│ sqrt = num ** 0.5 │
└────────────────────┘
↓
┌────────────────────┐
│ Print sqrt │
└────────────────────┘
↓
┌────────────┐
│ Stop │
└────────────┘
Program
# Program to find the square root of a number
num = float(input("Enter a number: "))
sqrt = num ** 0.5
print("The square root of", num, "is", sqrt)
input : 16
output: The square root of 16.0 is 4.0
program 3a): Write a program to calculate compound interest when principal, rate and number of periods are given.
Aim:
To write a Python program that calculates compound interest when the principal, rate of interest, and number of
periods are given.
Algorithm:
1. Start
2. Read the Principal (P), Rate of Interest (R), and Time period (T) from the user
3. Use the formula for Compound Interest:
A=P× ¿
Compound Interest = A − P
4. Display the Compound Interest and Total Amount
5. Stop
Flowchart:
┌──────────────┐
│ Start │
└──────┬───────┘
↓
┌──────────────────────────┐
│ Input P, R, T │
└──────────────────────────┘
↓
┌──────────────────────────┐
│ A = P * (1 + R/100) ** T │
└──────────────────────────┘
↓
┌──────────────────────────┐
│ CI = A - P │
└──────────────────────────┘
↓
┌──────────────────────────┐
│ Print CI and A │
└──────────────────────────┘
↓
┌──────────────┐
│ Stop │
└──────────────┘
Program:
Program to calculate Compound Interest
# Input principal, rate, and time
P = float(input("Enter the principal amount: "))
R = float(input("Enter the rate of interest: "))
T = float(input("Enter the time period in years: "))
# Calculate compound interest
A = P * (1 + R / 100) ** T
CI = A - P
# Display results
print("Compound Interest = ", round(CI, 2))
print("Total Amount = ", round(A, 2))
Input:
Enter the principal amount: 1000
Enter the rate of interest: 5
Enter the time period in years: 2
Output:
Compound Interest = 102.5
Total Amount = 1102.5
program 3b) Python Program to Calculate Simple Interest
Aim:
To write a Python program that calculates the Simple Interest (SI) when the Principal, Rate of Interest, and Time
period are given.
Algorithm:
1. Start
2. Read the Principal (P), Rate of Interest (R), and Time (T) from the user
3. Use the formula:
P×R×T
SI =
100
4. Display the Simple Interest and Total Amount (A = P + SI)
5. Stop
Flowchart:
┌──────────────┐
│ Start │
└──────┬───────┘
┌──────────────────────────┐
│ Input P, R, T │
└──────────────────────────┘
┌──────────────────────────┐
│ SI = (P * R * T) / 100 │
└──────────────────────────┘
┌──────────────────────────┐
│ A = P + SI │
└──────────────────────────┘
↓
┌──────────────────────────┐
│ Print SI and A │
└──────────────────────────┘
┌──────────────┐
│ Stop │
└──────────────┘
Program:
# Program to calculate Simple Interest
# Input principal, rate, and time
P = float(input("Enter the principal amount: "))
R = float(input("Enter the rate of interest: "))
T = float(input("Enter the time period in years: "))
# Calculate simple interest
SI = (P * R * T) / 100
A = P + SI
# Display results
print("Simple Interest = ", round(SI, 2))
print("Total Amount = ", round(A, 2))
Input:
Enter the principal amount: 1000
Enter the rate of interest: 5
Enter the time period in years: 2
Output:
Simple Interest = 100.0
Total Amount = 1100.0
Program 4 a) Read the name, address, email and phone number of a person through the keyboard
and print the details.
Aim:
To write a Python program that reads a person’s name, address, email, and phone number from the keyboard and
prints those details.
Algorithm:
1. Start
2. Read the name of the person
3. Read the address
4. Read the email ID
5. Read the phone number
6. Display all the entered details clearly
7. Stop
Flowchart:
┌────────────┐
│ Start │
└────┬───────┘
┌──────────────────────────┐
│ Input Name │
└──────────────────────────┘
┌──────────────────────────┐
│ Input Address │
└──────────────────────────┘
┌──────────────────────────┐
│ Input Email │
└──────────────────────────┘
↓
┌──────────────────────────┐
│ Input Phone Number │
└──────────────────────────┘
┌──────────────────────────┐
│ Print all details │
└──────────────────────────┘
┌────────────┐
│ Stop │
└────────────┘
Program:
# Program to read and print personal details
# Reading input from the user
name = input("Enter your name: ")
address = input("Enter your address: ")
email = input("Enter your email ID: ")
phone = input("Enter your phone number: ")
# Displaying the details
print("\n--- Personal Details ---")
print("Name:", name)
print("Address:", address)
print("Email ID:", email)
print("Phone Number:", phone)
Input:
Enter your name: Subbu
Enter your address: Hyderabad
Enter your email ID: sai@[Link]
Enter your phone number: 9876543210
Output:
--- Personal Details ---
Name: Subbu
Address: Hyderabad
Email ID: subbu@[Link]
Phone Number: 9876543210
Program 4 b) Write a python program to test whether a given number is even or odd
Aim:Write a python program to Test whether a given number is even or odd.
Program :
num = int(input("Enter a number: "))
if num % 2==0:
print("This is an even number.")
else:
print("This is an odd number.")
Output:
Enter a number: 5 This is an odd number
Program 4c) Python Program to Check Whether a Number is Prime or Not
Aim:
To write a Python program that checks whether a given number is a prime number or not.
Algorithm:
1. Start
2. Read a number from the user
3. If the number is less than 2, it is not prime
4. Otherwise, check divisibility from 2 to (number − 1):
o If the number is divisible by any of these, it’s not prime
o Else, it’s prime
5. Display the result
6. Stop
Flowchart:
┌────────────┐
│ Start │
└────┬───────┘
┌──────────────────────────┐
│ Input number (n) │
└──────────────────────────┘
┌──────────────────────────┐
│n<2? │
└──────────────────────────┘
↓ ↓
Yes No
↓ ↓
Print "Not Check divisibility
Prime" from 2 to n-1
┌──────────────────────────┐
│ Divisible? │
└──────────────────────────┘
↓ ↓
Yes No
↓ ↓
Print "Not Prime" Print "Prime"
↓
┌────────────┐
│ Stop │
└────────────┘
Program:
# Program to check whether a number is prime or not
num = int(input("Enter a number: "))
if num < 2:
print(num, "is not a prime number")
else:
for i in range(2, num):
if num % i == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
Input 1:
Enter a number: 7
Output 1:
7 is a prime number
Program 5 a) Print First 10 Natural Numbers
Aim:
To write a Python program to print the first 10 natural numbers using a for loop.
Algorithm:
1. Start
2. Use a for loop to iterate from 1 to 10
3. Print each number
4. Stop
Program:
# Program to print first 10 natural numbers
for i in range(1, 11):
print(i)
Output:
10
Program 5b) Print Multiplication Table of a Number
Aim:
To print the multiplication table of a given number using a for loop.
Algorithm:
1. Start
2. Read a number from the user
3. Use a for loop to iterate from 1 to 10
4. Multiply the number with loop variable and print the result
5. Stop
Program:
# Program to print multiplication table
num = int(input("Enter a number: "))
for i in range(1, 11):
print(num, "x", i, "=", num * i)
Input:
Enter a number: 5
Output:
5x1=5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50
Program 5c) Print a Pattern using for Loop
Aim:
To display a simple pattern using nested for loops.
Algorithm:
1. Start
2. Use an outer loop for number of rows
3. Use an inner loop to print * symbols
4. Stop
Program:
# Program to print a right triangle star pattern
for i in range(1, 6):
for j in range(1, i + 1):
print("*", end="")
print()
Output:
**
***
****
*****
Program 5 d)
AIM
To write a Python program using a for loop to print a number triangle pattern where each row prints a number
multiple times.
ALGORITHM
1. Start the program.
2. Set the starting number as 5.
3. Use a for loop to repeat from 5 down to 1.
4. For each number num, use another loop to print it (5 - num + 1) times.
5. After printing each row, move to the next line.
6. End the program.
FLOWCHART
Here is a simple text-based flowchart (you can draw this in your notebook):
┌───────────────┐
│ Start │
└───────┬───────┘
┌────────▼────────┐
│ num = 5 to 1 │
└────────┬────────┘
┌──────────▼───────────┐
│ repeat = 5 - num + 1 │
└──────────┬───────────┘
┌──────────▼──────────┐
│ print num 'repeat' │
│ times │
└──────────┬──────────┘
┌───────▼───────┐
│ next row │
└───────┬───────┘
┌───────▼───────┐
│ Stop │
└───────────────┘
PYTHON PROGRAM
for num in range(5, 0, -1): # from 5 to 1
for j in range(5 - num + 1): # repetition count
print(num, end=" ")
print()
INPUT
No input from user
(Values are fixed: 5 to 1)
OUTPUT
44
333
2222
11111
Program 6:
AIM
To write a Python program that checks whether the given input character is a digit, lowercase letter, uppercase
letter, or special character using an if–elif ladder.
Algorithm
1. Start
2. Read a character from the user
3. Check if the character is a digit
4. Else, check if it is a lowercase alphabet
5. Else, check if it is an uppercase alphabet
6. Else, it is a special character
7. Display the result
8. Stop
Flowchart (Text Representation)
┌───────────┐
│ Start │
└─────┬─────┘
↓
┌───────────────────┐
│ Read a character │
└─────────┬─────────┘
↓
┌────────────────────────┐
│ Is character a digit? │
└───────┬────────────────┘
│Yes
↓
┌────────────────────────┐
│ Print "Digit" │
└──────────┬─────────────┘
│No
↓
┌────────────────────────┐
│ Is lowercase letter? │
└───────┬────────────────┘
│Yes
↓
┌────────────────────────┐
│ Print "Lowercase" │
└──────────┬─────────────┘
│No
↓
┌────────────────────────┐
│ Is uppercase letter? │
└───────┬────────────────┘
│Yes
↓
┌────────────────────────┐
│ Print "Uppercase" │
└──────────┬─────────────┘
│No
↓
┌────────────────────────┐
│ Print "Special Char" │
└──────────┬─────────────┘
↓
┌───────────┐
│ Stop │
Python Program (if–elif ladder)
# Program to check type of a character
ch = input("Enter a character: ")
if [Link]():
print("Digit")
elif [Link]():
print("Lowercase Character")
elif [Link]():
print("Uppercase Character")
else:
print("Special Character")
input 1
Enter a character: 7
Output
Digit
PROGRAM 7:PYTHON PROGRAM to print all prime numbers in a given interval(use break)
1. AIM
To write a Python program to print all prime numbers in a given interval using a loop and the break statement.
✅ 2. Algorithm
1. Start
2. Read the starting number and ending number
3. For each number in the range:
o Assume it is prime
o Check divisibility from 2 to (number // 2)
o If divisible, mark as not prime and break the loop
4. If the number is still prime, print it
5. Continue till the end of interval
6. Stop
✅ 3. Flowchart (Text Representation)
┌──────────┐
│ Start │
└────┬─────┘
↓
┌──────────────────────┐
│ Read start & end │
└─────────┬────────────┘
↓
┌──────────────────────┐
│ For n in interval │
└─────────┬────────────┘
↓
┌──────────────────────────┐
│ Assume flag = 1 (prime) │
└─────────┬────────────────┘
↓
┌──────────────────────────┐
│ Check i = 2 to n//2 │
└─────────┬────────────────┘
↓
┌──────────────────────────┐
│ If n % i == 0 │
│ flag = 0, break │
└─────────┬────────────────┘
↓
┌──────────────────────────┐
│ If flag == 1 print n │
└─────────┬────────────────┘
↓
(repeat loop)
✅ 4. Python Program (using break)
# Program to print all prime numbers in a given interval
start = int(input("Enter start value: "))
end = int(input("Enter end value: "))
print("Prime numbers are:")
for num in range(start, end + 1):
if num > 1:
flag = 1
for i in range(2, num // 2 + 1):
if num % i == 0:
flag = 0
break # exit loop when not prime
if flag == 1:
print(num, end=" ")
✅ 5. Sample Input & Output
Input
Enter start value: 10
Enter end value: 30
Output
Prime numbers are:
11 13 17 19 23 29
Program 8:Write a program to convert a list and tuple into arrays
1. AIM
To write a Python program that converts a list and a tuple into NumPy arrays.
✅ 2. Algorithm
1. Start
2. Import the NumPy library
3. Create a list
4. Create a tuple
5. Convert the list into a NumPy array using [Link]()
6. Convert the tuple into a NumPy array using [Link]()
7. Display both arrays
8. Stop
✅ 3. Python Program
import numpy as np
# Given list and tuple
my_list = [10, 20, 30, 40]
my_tuple = (5, 15, 25, 35)
# Convert list and tuple to arrays
list_array = [Link](my_list)
tuple_array = [Link](my_tuple)
# Print results
print("Original List:", my_list)
print("Array from List:", list_array)
print("\nOriginal Tuple:", my_tuple)
print("Array from Tuple:", tuple_array)
✅ 4. Sample Input
(No input — values are already defined inside the program)
✅ 5. Sample Output
Original List: [10, 20, 30, 40]
Array from List: [10 20 30 40]
Original Tuple: (5, 15, 25, 35)
Array from Tuple: [ 5 15 25 35 ]
Program 9:Write a program to find common values between two arrays
1. AIM
To write a Python program to find the common values between two arrays.
✅ 2. Algorithm
1. Start
2. Create two arrays (lists or NumPy arrays)
3. Convert them into sets OR use NumPy intersection method
4. Find the common elements
5. Display the result
6. Stop
✅ 3. Python Program (Simple – Using Sets)
# Program to find common values between two arrays
arr1 = [10, 20, 30, 40, 50]
arr2 = [30, 40, 60, 70, 80]
# Find common values
common_values = list(set(arr1) & set(arr2))
print("Array 1:", arr1)
print("Array 2:", arr2)
print("Common Values:", common_values)
✅ 4. Output
Array 1: [10, 20, 30, 40, 50]
Array 2: [30, 40, 60, 70, 80]
Common Values: [30, 40]
Program 10: PALINDROME
1. AIM
To write a Python function named palindrome that takes a string as input and returns True if the string is a
palindrome and False otherwise, using the built-in function len() to check the length.
✅ 2. Algorithm
1. Start
2. Define a function named palindrome(s)
3. Find the length of the string using len(s)
4. Loop from index 0 to length // 2
5. For each character:
o Compare the character at position i with the character at length - 1 - i
6. If any pair does not match → return False
7. If all pairs match → return True
8. Stop
✅ 3. Python Program
def palindrome(s):
length = len(s)
# check characters from both ends
for i in range(length // 2):
if s[i] != s[length - 1 - i]:
return False
return True
# Main program
string = input("Enter a string: ")
result = palindrome(string)
if result:
print("It is a palindrome")
else:
print("It is not a palindrome")
✅ 4. Sample Input & Output
Input 1
Enter a string: madam
Output 1
It is a palindrome
Input 2
Enter a string: hello
Output 2
It is not a palindrome
Program 11:write a function called is_sorted that takes a list as a parameter and returns true if the list is sorted in
ascending order and false otherwise
1. AIM
To write a Python function is_sorted() that takes a list as input and returns True if the list is sorted in ascending
order, otherwise returns False.
✅ 2. Algorithm
1. Start
2. Define a function is_sorted(list1)
3. Loop from index 0 to length–2
4. Compare each element with the next element
5. If any element is greater than the next, return False
6. If loop completes, return True
7. Stop
✅ 3. Flowchart (Text Representation)
┌──────────┐
│ Start │
└────┬─────┘
↓
┌────────────────────┐
│ Read the list │
└─────────┬──────────┘
↓
┌────────────────────┐
│ For i = 0 to n-2 │
└─────────┬──────────┘
↓
┌──────────────────────────┐
│ Is list[i] > list[i+1]? │
└───────┬──────────────────┘
│Yes
↓
┌─────────────────────────┐
│ Return False │
└──────────┬──────────────┘
│No
↓
(repeat loop)
↓
┌─────────────────────────┐
│ Return True │
└──────────┬──────────────┘
↓
┌──────────┐
│ Stop │
└──────────┘
✅ 4. Python Program
def is_sorted(lst):
# Compare each element with the next
for i in range(len(lst) - 1):
if lst[i] > lst[i + 1]:
return False
return True
# Main program
numbers = list(map(int, input("Enter numbers separated by space: ").split()))
result = is_sorted(numbers)
if result:
print("The list is sorted in ascending order.")
else:
print("The list is NOT sorted in ascending order.")
✅ 5. Sample Input & Output
Input 1
Enter numbers separated by space: 1 2 3 4 5
Output 1
The list is sorted in ascending order.
Input 2
Enter numbers separated by space: 10 5 7 9
Output 2
The list is NOT sorted in ascending order.