Naveen Python Lab
Naveen Python Lab
INFORMATION TECHNOLOGY
(AIIT)
Naveen Singh
Enrolment No. A710145023049
Python (Django & Kivy) Lab MCA
Semester – 1
2
Index
Sl.No Experiments Page No
1 Python program for Accepting input from user and 7
print it
19 15
Write a python program to convert tuple into string
24 18
Python program to check if the string is a pangram.
3
25 Python program takes two lists as inputs and prints 18
common Output in the third list.
27 Fibonacci series 19
28 Kivy Installation 20
29 Creating simple hello world program 21
4
42 a) Python Programs on lambda function 50 - 51
b) Programs on _init_function
44 Program on matplotlib 53 - 56
45 Program on pandas 57 - 59
46 Program on Web scraping using beautifulsoup 60 - 62
47 Programs on scipy 63 -64
5
Practical No
1
Python program for Accepting input from user and print it
Practical No 2
Printing addition, subtraction, multiplication and division of two
numbers using user input
6
Practical No
Write a python program to find
Practical No 3
Finding data type of value assigned to a variable
4
Python if the number entered by
user is even or odd
Practical No 5
Write a python program to find the number entered by user is positive
or not
7
Practical No
Write a program to find
6 the largest among
three
numbers
Practical No 7
Write a python program to find if the person is eligible for voting or
not.
8
Practical No
Write a python program to find
9
Practical No
Write a python program to find
8
if the number is divisible
by 12 or not
Practical No 9
Write a python program to calculate the electricity bill according to
10
Practical No
Write a python program to
10
print the last two digit of a
number
Practical No 11
Write a python program to display the grade based on student's
percentage
11
Practical No
12
Practical No
Write a python program to
12 Multiplication
table of a given number
13
Practical No
Practical No 13
Sum of all odd and even number in a given range
14
Practical No
14
To accept a word from user and reverse it
Practical No 15
To find if a number is armstrong number or not
15
Practical No
16
To print all the number in a given range
16
Practical No
Practical No 17
Python program to unpack tuple in variables
18
Since tuple is immutable that means we cannot add an element in a
tuple. Write a program to create a new tuple by merging tuples with
the + operator.
17
Practical No
Practical No 19
Write a python program to convert tuple into string
18
Practical No
program to
20
Write a check whether element exist in tuple or
not
Practical No 21
Write a program to reverse a tuple
19
Practical No
program to
22
Write a multiply all the elements of tuple
Practical No 23
Python program to add ed at the end of a given verb string
20
Practical No
program to
24
Python check if the string is a pangram.
Practical No 25
Python program to take two lists as inputs and prints common Output
in the third list.
21
Practical No
program to
26
Python find if the number is a perfect number or not.
22
Practical No
program to
Practical No 27
Fibonacci series
23
Practical No
28
Kivy Installation
Step 1: Update the pip and wheel before installing kivy by entering this
command in cmd-
python -m pip install --upgrade pip wheel setuptools
24
Practical No
29 Creati
ng simple hello world program
import kivy
kivy.require('1.10.0')
class HelloKivy(App):
helloKivy = HelloKivy()
helloKivy.run()
Output:
25
Practical No
30 Kivy
Program to display Image widget
import kivy from kivy.app import App
kivy.require('1.9.0') from
kivy.uix.image import Image,AsyncImage
class MyApp(App):
def build(self):
return AsyncImage(source
='https://cuet-2023-public.s3.ap-south-1.amazonaws.com/site-admin23/
ac61e5f2feb 4b0f534b1bc4794cdc772cf1679dca69cc262d5c710ef24b321a83/Amity
%20University%20Mum bai1677911309_upload_logo.jpg')
MyApp().run()
Output:
26
Practical No
31
Kivy Program to create Button
from kivy.app import App from
kivy.uix.button import Button from
kivy.uix.label import Label from
kivy.uix.boxlayout import BoxLayout
class ButtonApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
self.message_label = Label(text='')
layout.add_widget(button)
layout.add_widget(self.message_label)
return layout
if __name__ == '__main__':
ButtonApp().run()
27
Output:
Onclick
32 Kivy
Program to display Label and checkboxes
import kivy from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label from
kivy.uix.checkbox import CheckBox from
28
Practical No
kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import
BoxLayout class check_box(BoxLayout):
class CheckBoxApp(App):
def build(self):
return check_box()
if __name__ == '__main__':
CheckBoxApp().run()
Output:
29
33
Installation of django
Step 1: Create virtual environment in django: We should first go to the
directory where we want to create the virtual environment then we type the
following command to create virtual environment in django.
python -m venv env_site
Step 2: Activate the virtual environment: Run the activation script located in
the Scripts directory within the virtual environment folder.
env_site\Scripts\activate.bat
30
Practical No
pip install django
Step 6: Start the server- Start the server by typing following command in
cmd-
python manage.py runserver
31
32
Practical No
34
Hello world program in django
Step 1: Create a new Django project by running:
django-admin startproject hello_project
This will create a directory named hello_project with the basic structure of a
Django project.
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python manage.py startapp hello_app
def hello_world(request):
return HttpResponse("Hello, World!")
33
Open the urls.py file in the hello_project directory and include the URLs of
the hello_app. urls.py
from django.contrib import admin
from django.urls import path,
include
urlpatterns = [ path('admin/',
admin.site.urls),
path('app/',
include('hello_app.urls')), ]
Step 7: Start the Django development server:
python manage.py runserver
Output:
35
Program to print date and time using django.
Step 1: Create a new Django project by running:
django-admin startproject hello_project
This will create a directory named hello_project with the basic structure of a
Django project.
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python manage.py startapp hello_app
34
Practical No
Step 4: Define a View
Open the views.py file in the hello_app directory, and import the necessary
modules: views.py
from django.http import HttpResponse
from datetime import datetime
def current_datetime(request):
now = datetime.now() formatted_datetime = now.strftime("%Y-
%m-%d %H:%M:%S") return HttpResponse(f"Current Date and Time:
{formatted_datetime}")
urlpatterns = [ path('admin/',
admin.site.urls),
path('app/',
include('hello_app.urls')), ]
Step 7: Start the Django development server:
35
python manage.py runserver
Output:
36
Program to print time after 10 hrs through dynamic URLs using django
Step 1: Create a new Django project by running:
django-admin startproject hello_project
This will create a directory named hello_project with the basic structure of a
Django project.
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python manage.py startapp hello_app
def time_info(request):
36
Practical No
now = datetime.now() formatted_current_time =
now.strftime("%Y-%m-%d %H:%M:%S")
def time_info(request):
now = datetime.now() formatted_current_time =
now.strftime("%Y-%m-%d %H:%M:%S")
return HttpResponse(response_text)
from django.urls import path
from .views import time_info
37
from datetime import datetime,
timedelta
def time_info(request):
now = datetime.now() formatted_current_time =
now.strftime("%Y-%m-%d %H:%M:%S")
38
response_text = f"Current Time: {formatted_current_time}<br/>"
response_text += f"Time after 10 hours:
{formatted_time_after_10_hours}"
return HttpResponse(response_text)
from django.urls import path
from .views import time_info
urlpatterns = [ path('admin/',
admin.site.urls),
path('app/',
include('hello_app.urls')), ]
Step 7: Start the Django development server:
python manage.py runserver
Output:
Practical No 37
Program to demonstrate Template in django
Step 1: Create a new Django project by running:
39
django-admin startproject my_project
This will create a directory named my_project with the basic structure of a
Django project.
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python manage.py startapp my_app
40
} return render(request, 'greeting.html',
context)
Step 7: Configure URLs
Create a new file named urls.py inside the my_app directory
urls.py
Output:
41
Practical No 38
Creating Django admin interface
Step 1: Create a new Django project by running:
django-admin startproject new_project
This will create a directory named new_project with the basic structure of a
Django project.
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python manage.py startapp new_app
class MyModel(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
def __str__(self):
return self.name
42
Step 5: Create a Superuser: Before using the admin interface, you need to
create a superuser account. Run the following command to create a
superuser:
python manage.py createsuperuser
This command will ask you to enter a username, email address, and
password for the superuser
Output:
43
Practical No 39
Creating Django Models
Step 1: Create a new Django project by running:
django-admin startproject new_project
This will create a directory named new_project with the basic structure of a
Django project.
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python manage.py startapp new_app
44
Step 4: Open settings.py file in project directory
settings.py
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'new_app',
]
def __str__(self):
return self.name
45
Output:
Practical No 40 CRUD
operations on models
tep 1: Create a new Django project by running:
django-admin startproject new_project
This will create a directory named new_project with the basic structure of a
Django project.
46
Step 2: Navigate to the Project Directory
cd new_project
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python manage.py startapp new_app
Output:
Create:
47
Update:
Update:
48
Delete:
Practical No 41
a) Python Programs on functions.
49
50
b) Programs on recursion to find the factorial of a number
Practical No 42
a) Python Programs on lambda function
51
b) Programs on _init_function
52
53
Practical No 43
a) Create a class which has init function and normal def function for
displaying the details
54
Practical No 44
Program on matplotlib
55
56
57
58
Practical No 45
Program on pandas
59
60
61
Practical No 46 Program on
Web scraping using beautifulsoup
62
63
Practical No 47
Programs on scipy
64
65
66