PYTHON Activities
PYTHON Activities
ACTIVITY-1
AIM: Print a string using a print statement
ACTIVITY-2
AIM: Print given string using indentation (space between characters.
ACTIVITY-3
AIM: Define Integer Variables, floating variables and string variables.
ACTIVITY-4
AIM: Write a program to add numbers and strings to the current list
using the append list method.
ACTIVITY-5
AIM: Write a python program to add, subtract, multiply and divide
given two numbers by using arithmetic operators.
ACTIVITY-6
AIM: Write a python program multiplying strings to form string with
repeating sequence.
ACTIVITY-7
AIM: Write a Python program to get the largest number from a list by
using max and min commands.
ACTIVITY-8
AIM: Write a Python program to find whether a given number
(accept from the user) is even or odd by using if else command.
ACTIVITY-9
AIM: Write a Python program to create a histogram from a given list
of integers by using for while loop.
ACTIVITY-10
AIM: Write a Python program to compute the greatest common
divisor (GCD) of two positive integers by using loop.
ACTIVITY-11
AIM: Write a Python program to get the least common multiple
(LCM) of two positive integers using if else and while commands.
ACTIVITY-12
AIM: Write a Python program to sort (ascending and descending) a
dictionary by value.
ACTIVITY-13
AIM: Write a Python program to create a tuple.
ACTIVITY-14
AIM: Write a Python program to create a tuple with different data
types.
ACTIVITY-15
AIM: Write a Python program to create a set.
ACTIVITY-16
AIM: Write a Python program to add member(s) in a set.
ACTIVITY-17
AIM: Write a Python program to find maximum and the minimum
value in a set.
ACTIVITY-18
AIM: Write a Python program to find the length of a set.
ACTIVITY-19
AIM: Write a Python program to convert temperatures to and from
Centigrade to Fahrenheit.
ACTIVITY-20
AIM: Write a Python program to find Fibonacci series.
ACTIVITY-21
AIM: Write a python program to find factorial using function in
Python IDLE.
ACTIVITY-22
AIM: Write a python program to find whether the given string is
palindrome or not by using function.
ACTIVITY-23
AIM: Write a python class to reverse a string word by word.
ACTIVITY-24
AIM: Write a python class named as circle by a radius and two
methods of computer area and perimeter of a circle.
ACTIVITY-25
AIM: Write a python program to sort a list of elements using bubble
sort algorithm.
ACTIVITY-26
AIM: Write a python program to copy content of a file to another
file.
OUTPUT-
ACTIVITY-27
AIM: Write a python program to find the frequency of words in a file.
ACTIVITY-28
AIM: Write a python program to illustrate exception handling.
ACTIVITY-29
AIM: Develop a python code to read a text file, copy the contents to
another file after removing the blank lines.
OUTPUT-
ACTIVITY-30
AIM: Create a database in MySQL and connect using python.
Step 1: Install necessary libraries
Make sure you have MySQL installed on your computer. Also, install the
required Python libraries: mysql-connector-python.
Open your MySQL client (e.g., MySQL Command line) and create a
new database named "pythondb”.
Output-
ACTIVITY-31
AIM: Perform CRUD operations on MySQL database using python.
Output
Step 3 – Insert Data into trainee tables
Code
Output
Output
Code
Output
Step 6 – DELETE Data from the trainee tables
Code
Output
ACTIVITY-32
AIM: Perform CRUD operations on Mongo DB database using python.
To perform CRUD operations (Create, Read, Update, Delete) on a
MongoDB database using Python
Step 1: Install the ‘pymongo’ library, which is the official Python driver for
MongoDB.
1.Create
OUTPUT-
2.Read
3.Update
Output
4.Delete
Output
ACTIVITY-33
AIM: Create a class with related data elements and methods. Write
functionalities for basic operations.
ACTIVITY-34
AIM: Python program using a flag to validate if the input given by the
user, is an integer.
ACTIVITY-35
AIM: Create a simple python Flask app with at least 3 basic routes.
Step 1: Install Flask Make sure you have Flask installed. If not, you can install it
using the following command:
app = Flask(__name__)
@app.route('/')
def home():
return '<h1>Welcome to My Web Page</h1><footer><a href =
"/contact">Contact us</a><br><a href = "/about">About</a></footer>'
@app.route('/about')
def about():
return '<header><a href ="/">Home Page</a></header><h1>About
Us</h1><p>Hello everyone my name is Sudhir<br> I am trainee at NSTI
Noida.</p><footer><a href = "/contact">Contact</a></footer>'
@app.route('/contact')
def contact():
return '<header><a href ="/">Home Page</a></header><h1>Contact Us</h1>You
can reach us at [email protected].<p><footer><a href =
"/about">Contact</a></footer>'
if __name__ == '__main__':
app.run(debug=True)
Step 5: Run the App At the end of your app.py file, add the following code to
run the app:
if __name__ == '__main__':
app.run(debug=True)
Step 6: Run the App Open a terminal, navigate to the directory where your
app.py file is located, and run the following command:
python app.py
Step 7: Access the Routes Open a web browser Click on urls and visit the
following URLs to access the different routes:
Home: http://127.0.0.1:5000/
About: http://127.0.0.1:5000/about
Contact: http://127.0.0.1:5000/contact
DJANGO
ACTIVITY-1
Aim: Install Django framework libraries in python and test for
installation.
STEP:3 Open Pycharm and Create a new project where you want.
py --version
django-admin --version
Step: 4 To create a new project.
cd Project_Name(project)
py manage.py runserver
After clicking you will see the Django was successfully installed page.
ACTIVITY-2
Aim: Setup first Django application
cd Project_Name(project)
Go to three lines on top > New > Python File > Drop a name >Enter
Type Following Code to access all urls in project urls.py file in app
urls.py file
Step: 7 Now go to project urls.py and write code then save the file.
urlpatterns = [
path (‘ ’,include(‘application_name.urls’),
path(‘admin/’,admin.site.urls),
]
Step: 8 Then go to project
cd Project_name(project)
py manage.py runserver
OUTPUT-
ACTIVITY-3
Aim: Creating Django application with MVT architecture
py manage.py migrate
py manage.py shell
STEP: 10 Now Add the record into table.
py manage.py runserver
Output
ACTIVITY-4
Aim: Create Django application that handles file uploading
Step: 1 Create new project folder for file uploading and install Django
in this folder
Step: 2 go to your terminal and Create a Project through the
terminal.
upload_file.html:
upload_success.html
Step 8 Now go to your app and create new directory with media
name
Output
ACTIVITY-5
Aim: Create Django application that reads data from CSV and
display on page
py manage.py migrate
STEP: 8 Now we need to execute and check SQL statement.
py manage.py shell
py manage.py runserver
Output
STEP:17 Go to the index.html then add a link over here after the
table tag
Check Output