0% found this document useful (0 votes)
10 views22 pages

Python Programming Basics and Exercises

The document is a Python programming file authored by Priyanka Banerjee, detailing various experiments and programs related to Python basics, including installation, execution modes, and practical applications like calculating salary, checking even/odd numbers, and working with data structures. Each experiment includes aims, theories, procedures, and sample programs with expected outputs. The content serves as a comprehensive guide for learning and practicing Python programming concepts.
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)
10 views22 pages

Python Programming Basics and Exercises

The document is a Python programming file authored by Priyanka Banerjee, detailing various experiments and programs related to Python basics, including installation, execution modes, and practical applications like calculating salary, checking even/odd numbers, and working with data structures. Each experiment includes aims, theories, procedures, and sample programs with expected outputs. The content serves as a comprehensive guide for learning and practicing Python programming concepts.
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 PROGRAMMING FILE

• Name: Priyanka Banerjee


• Roll No: 1ETMCA20251011
• Department: FET
• Course: MCA (CSCD)
• Subject: Python Programming
• Subject code: TCS501
• Submitted to: Mr Suvendu Kumar Nayak
Index:

1. To install the latest version of python


2. Execute a simple python program in interactive mode
3. Execute a simple python program in script mode
4. To install anaconda navigator and jupyter notebook
5. To understand and demonstrate the use of assignment operator in
python
6. Write a program to print the area and perimeter of a circle
7. Write a program to accept basic from user and calculate TA,DA, and
Total. “TA” is 5% of basic, “DA” is 7% of basic. Deduct 1.5% of total
salary as income tax and show the amount payable
8. Write a program to input value of a and b and find the greater
number between two
9. Write a program to input three side of a triangle and print whether
the triangle is equilateral or isosceles or scalene
[Link] a program to input the mark of math and science from the
user. If we secure more then 80 in both the subject, a bike will be
gifted. If we secure more then 80 in any one subject, a cycle will be
gifted else slap will be given
[Link] a program to check a number is even or odd
[Link] a program to calculate electric bill as per following condition. If
unit consume is more than 200, then Rs 15 per unit is charged. If
more then 100 and less than 201, then Rs. 10 per unit will be
charged. If less then 101, then rs.5 per unit will be charged.
[Link] a program to discount in reliance jio is given as per following
condition: 5% discount if total amount is greater then 5000 and the
gender is male, 7% discount if the total amount is greater then 7000
and the gender is female
[Link] a python program to create a list, add elements, remove an
element and display the final list.
[Link] a python program to create a tuple and access its elements
using indexing.
[Link] a python program to create a set, add a new element, and
remove an element.
[Link] a python program to create a dictionary, update a value, and
print all key-value pairs.
[Link] a python program to check whether a number is a palindrome
or not using user-defined functions.
Experiment no. 1:

Aim:
To install the latest version of python on the computer system.

Procedure/steps:
Click “window key + R”
Type- cmd (command)
Type-python (to check whether python is installed or not)
If installed then we can start programming
If not installed then it’ll show “get”
We simply click on the get to install the python
Other option:
Open your browser and go to the official python website:
Click on download python [latest version]
After the download completes, open the installer file
In the setup window:
Check the box add python to path
Click install now
Wait until the installation complete
Once done you’ll see setup was successful message
To verify installation:
Open command prompt
And start type code:
Python
Experiment no. 2:

Aim:

Execute a simple python program in interactive mode.

Theory:
Python provide two modes to run programs:
Interactive mode
Script mode

In interactive mode every command we type is immediately executed and the result is
displayed instantly

Procedure/steps:
Open python idle from the start menu
The window that opens shows the python prompt
Type the python statement or command after the prompt
Press enter to execute the command
The result appear immediately on the next line

Program:
a= 10
b= 3
c= a/b
print(c)
3.333333333333
d= a//b
print(d)

3
c= a%b
print(c)
1

a= -10
b= 3
c= a%b
print(c)
2

a= 10
b= -3
c= a%b
print(c)
-2

a= 10
b= 2
c= a**b
print(c)
100
Experiment no.3:

Aim:
Execute a simple python program in script mode

Theory:
Python provide two modes to run programs:

1. Interactive mode
2. Script mode

In script mode the program is saved and can be reused or edited later. It is suitable for
writing longer programs

Procedure/steps:
Open python idle
Click on file – new file
Type python code in the new file
Save the file with [Link] extension
To run the program click run - run module
The output will appear in the python shell window

Program:
a= 10
b= 5
c= a+b
print(c)
15

Experiment no. 4:
Aim:
To install anaconda navigator and jupyter notebook for running python programs

Theory:
Anaconda is a free and open source distribution of python used for data science, machine
learning, and scientific computing. It comes with many pre-installed libraries and tools such
as jupyter notebook, spyder, and numpy.

Jupyter notebook is an interactive environment where we can write and execute python code
is separate cells, visualize data, and add text or formulas.

Installing anaconda automatically installs jupyter notebook

Procedure/steps:
Open web browser and go to the official anaconda website
Click on download and choose the installer for your operating system
Once downloaded, open the installer file
Follow the installation process
Click next
Accept the license agreement
Choose just me- click next
Select installation location
Check the option add anaconda to my path environment variable
Click install
Wait for the installation to complete then click finish
Open anaconda navigator then we will see several tools
Click on launch under jupyter notebook
Jupyter notebook will open in browser
Click- new
Strat writing code

Experiment no. 5:

Aim:
To understand and demonstrate the use of assignment operator in python
Theory:
Assignment operator are used to assign values to variables
They can also perform arithmetic operation and update the variable in a single step

Operator description
= assign value
+= add and assign
-= substract and assign
*= multiply and assign
/= divide and assign
%= modulus and assign
**= exponent and assign
//= floor divide and assign

program:
a=10
print(a)
a+=5
print(a)
a-=3
print(a)
a*=2
print(a)
a/=4
print(a)
a%=3
print(a)
a**=2
print(a)
Experiment no. 6:

Aim:
Write a program to print the area and perimeter of a circle

Program:
r=20
perimeter=2*3.14*r
area= 3.14*r*r
print("perimeter=", perimeter)
print("area is",area)

output:
perimeter= 125.60000000000001
area is 1256.0
Experiment no. 7:

Aim:
Write a program to accept basic from user and calculate TA, DA and Total. “TA” is 5% basic,
“DA” is 7% of basic. Deduct 1.5% of total salary as income tax and show the amount
payable

Program:
basic= float(input("enter basic"))

ta= basic*0.05

da= basic*0.07

total= basic+ta+da

tax= total*0.015

net_pay= total-tax

print("TA (5% of basic) =", ta)

print("DA (7% of basic) =", da)

print("total salary =", total)

print("income tax(1.5% of total) =", tax)

print("net amount payable =",net_pay)

output:
enter basic 20000
TA (5% of basic) = 1000.0
DA (7% of basic) = 1400.0000000000002
total salary = 22400.0
income tax(1.5% of total) = 336.0
net amount payable = 22064.0
Experiment no. 8:

Aim:
Write a program to input value of a and b and find the greater number between two

Algorithm/logic:
Input two number a and b
Compare the values using if-else statement
If a>b, print that a is greater
Otherwise, print that b is greater

Program:

a=int(input("enter a"))
b=int(input("enter b"))
if a>b:
print("a is the greater number")
elif b>a:
print("b is the greater number")

else:
print("both a and b are equal")

output:
enter a 20
enter b 30
b is the greater number
Experiment no.9:

Aim:
Write a program to input three side of a triangle and print whether the triangle is equilateral
or isosceles or scalene

Theory:
Equilateral: all three sides are equal
Isosceles: any two sides are equal
Scalene: all sides are different

Program:

a=int(input("enter 1st side of a triangle"))


b=int(input("enter 2nd side of a triangle"))
c=int(input("enter 3rd side of a triangle"))
if(a == b and b == c and c == a):
print("equilateral triangle")
elif(a == b or b == c or c == a):
print("triangle is isoscles")
else:
print("scalene triangle")

output:
enter 1st side of a triangle 6
enter 2nd side of a triangle 6
enter 3rd side of a triangle 4
triangle is isoscles
Experiment no. 10:

Aim:
Write a program to input the mark of math and science from the user. If we secure more then
80 in both the subject, a bike will be gifted. If we secure more then 80 in any one subject, a
cycle will be gifted else slap will be given

Program:

a=int(input("enter marks of math"))


b=int(input("enter marks of science"))

if(a>80 and b>80):


print("congratulation you will get a bike")
elif(a>80 or b>80):
print("good job! you will get a cycle")
else:
print(" oh no! you will get a slap")

output:

enter marks of math 88


enter marks of science 93
congratulation you will get a bike

enter marks of math 60


enter marks of science 82
good job! you will get a cycle

enter marks of math 60


enter marks of science 55
oh no! you will get a slap
Experiment no.11:

Aim:
Write a program to check a number is even or odd

Program:

num=int(input("enter a number:"))
if num % 2 == 0:
print("the number is even")
else:
print("the number is odd")
output:

enter a number: 5
the number is odd

enter a number: 6
the number is even

Experiment no. 12:

Aim:
Write a program to calculate electric bill as per following condition. If unit consume is more
than 200, then rs 15 per unit is charged. If more then 100 and less than 201, then rs. 10 per
unit will be charged. If less then 101, then rs.5 per unit will be charged

Program:

units=int(input("enter the number of units consumed:"))


if units>200:
bill=units*15
elif units>100 and units<=200:
bill=units*10
else:
bill=units*5

print("Total Electricity Bill=Rs",bill)

output:
enter the number of units consumed: 250
Total Electricity Bill=Rs 3750
Experiment no. 13:

Aim:
Write a program to discount in reliance jio is given as per following condition: 5% discount if
total amount is greater then 5000 and the gender is male, 7% discount if the total amount is
greater then 7000 and the gender is female

Program:

amount=int(input("enter total amount:"))


gender=input("enter gender(male/female):")
if amount>5000 and gender=="male":
discount=amount*5/100
elif amount>7000 and gender=="female":
discount=amount*7/100
else:
discount=0
final_amount=amount-discount
print("discount given:Rs", discount)
print("final amount to pay:Rs",final_amount)

output:1
enter total amount: 6000
enter gender(male/female): male
discount given:Rs 300.0
final amount to pay:Rs 5700.0

output:2
enter total amount: 8000
enter gender(male/female): female
discount given:Rs 560.0
final amount to pay:Rs 7440.0

Experiment no. 14:

Aim:
Write a python program to create a list, add elements, remove an element and display the
final list.

Program:

my_list = []

my_list.append(10)
my_list.append(20)
my_list.append(30)
my_list.append(40)

print("List after adding elements:", my_list)

my_list.remove(20)
print("Final list after removal:", my_list)

Output:
List after adding elements: [10, 20, 30, 40]
Final list after removal: [10, 30, 40]

Experiment no. 15:

Aim:
Write a python program to create a tuple and access its elements using indexing.

Program:
my_tuple = (10, 20, 30, 40, 50)

print("First element:", my_tuple[0])


print("Third element:", my_tuple[2])
print("Last element:", my_tuple[-1])

output:
First element: 10
Third element: 30
Last element: 50
Experiment no. 16:

Aim:
Write a python program to create a set, add a new element, and remove an element.

Program:
my_set = {10, 20, 30}

print("Original set:", my_set)

my_set.add(40)
print("After adding 40:", my_set)

my_set.remove(20)
print("After removing 20:", my_set)

output:
Original set: {10, 20, 30}
After adding 40: {40, 10, 20, 30}
After removing 20: {40, 10, 30}

Experiment no. 17:

Aim:
Write a python program to create a dictionary, update a value, and print all key-value pairs.

Program:
student = {
"name": "Alice",
"age": 20,
"grade": "A"
}

print("Original dictionary:", student)

student["grade"] = "A+"

print("Updated dictionary:", student)

print("\nKey–Value Pairs:")
for key, value in [Link]():
print(key, ":", value)

output:
Original dictionary: {'name': 'Alice', 'age': 20, 'grade': 'A'}
Updated dictionary: {'name': 'Alice', 'age': 20, 'grade': 'A+'}

Key–Value Pairs:
name : Alice
age : 20
grade : A+

Experiment no. 18:

Aim:
Write a python program to check whether a number is a palindrome or not using user-
defined functions.

Program:

def is_palindrome(num):

num_str = str(num)

if num_str == num_str[::-1]:
return True
else:
return False

number = int(input("Enter a number: "))

if is_palindrome(number):
print(number, "is a palindrome.")
else:
print(number, "is not a palindrome.")

output:
Enter a number: 15
15 is not a palindrome.

You might also like