AMITY INSTITUTE OF
INFORMATION TECHNOLOGY
(AIIT)
Naveen Singh
Enrolment No. A710145023049
Python (Django & Kivy) Lab MCA
Semester – 1
2
Index
[Link] Experiments Page No
1 Python program for Accepting input from user and 7
print it
2 Printing addition, subtraction, multiplication and 7
division of two numbers using user input
3 7
Finding data type of value assigned to a variable
4 Write a Python program to find if the number entered 8
by user is even or odd
5 Write a python program to find the number entered by 8
user is positive or not
6 Write a python program to find the largest among three 9
numbers
7 Write a python program to find if the person is eligible 9
for voting or not.
8 Write a python program to find if the number is 10
divisible by 12 or not
9 Write a python program to calculate the electricity bill 10
according to
10 Write a python program to print the last two digit of a 11
number
11 Write a python program to display the grade based on 11
student's percentage
12 Multiplication table of a given number 12
13 12
Sum of all odd and even number in a given range
14 To accept a word from user and reverse it 13
15 To find if a number is armstrong number or not 13
16 To print all the number in a given range 14
17 Python program to unpack tuple in variables 14
18 Since a tuple is immutable that means we cannot add 15
an element in a tuple. Write a program to create a new
tuple by merging tuples with the + operator
19 15
Write a python program to convert tuple into string
20 Write a program to check whether element exist in 16
tuple or not
21 Write a program to reverse a tuple 16
22 Write a program to multiply all the elements of tuple 17
23 Python program to add ed at the end of a given verb 17
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.
26 Python program to find if the number is a perfect 19
number or not.
27 Fibonacci series 19
28 Kivy Installation 20
29 Creating simple hello world program 21
30 Kivy Program to display Image widget 22
31 Kivy Program to create Button 23 - 24
32 Kivy Program to display Label and checkboxes 25 - 26
33 Installation of django 27 -28
34 Hello world program in django 29 - 30
35 Program to print date and time using django 31 - 32
36 Program to print time after 10 hrs through dynamic 33 -35
URLs using django
37 Program to demonstrate Template in django 36 - 38
38 Creating Django admin interface 39 - 41
39 Creating Django Models 42 - 44
40 CRUD operations on models 45 - 47
41 a) Python Programs on functions 48 - 49
b) Programs on recursion to find the factorial of a
number
4
42 a) Python Programs on lambda function 50 - 51
b) Programs on _init_function
43 a) Create a class which has init function and normal 52
def function for displaying the details b) Program to
print star pattern
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
Step 2: Install the dependencies-
python -m pip install docutils pygments pypiwin32
[Link].sdl2 [Link] python -m pip install
[Link] python -m pip install [Link]
Step 3: Install kivy.
python -m pip install kivy
24
Practical No
29 Creati
ng simple hello world program
import kivy
[Link]('1.10.0')
from [Link] import App from
[Link] import Label
class HelloKivy(App):
def build(self): return
Label(text ="Hello World")
helloKivy = HelloKivy()
[Link]()
Output:
25
Practical No
30 Kivy
Program to display Image widget
import kivy from [Link] import App
[Link]('1.9.0') from
[Link] import Image,AsyncImage
class MyApp(App):
def build(self):
return AsyncImage(source
='[Link]
ac61e5f2feb 4b0f534b1bc4794cdc772cf1679dca69cc262d5c710ef24b321a83/Amity
%20University%20Mum bai1677911309_upload_logo.jpg')
MyApp().run()
Output:
26
Practical No
31
Kivy Program to create Button
from [Link] import App from
[Link] import Button from
[Link] import Label from
[Link] import BoxLayout
class ButtonApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
self.message_label = Label(text='')
button = Button(text='Click me', size_hint=(None, None),
size=(200, 50), pos_hint={'center_x': 0.5, 'center_y': 0.5},
background_color=(1, 1, 0, 1))
[Link](on_press=self.on_button_press)
layout.add_widget(button)
layout.add_widget(self.message_label)
return layout
def on_button_press(self, instance):
self.message_label.text = 'Hello Everyone\nWelcome to Kivy'
if __name__ == '__main__':
ButtonApp().run()
27
Output:
Onclick
32 Kivy
Program to display Label and checkboxes
import kivy from [Link] import App
from [Link] import Widget
from [Link] import Label from
[Link] import CheckBox from
28
Practical No
[Link] import GridLayout
from [Link] import
BoxLayout class check_box(BoxLayout):
def __init__(self, **kwargs): super(check_box,
self).__init__(**kwargs) [Link] = 'vertical'
self.add_widget(Label(text='Subjects Studied',
halign='center')) checkbox_layout = GridLayout(cols=2,
spacing=-20)
checkbox_layout.add_widget(Label(text='Male')) [Link]
= CheckBox(active=False)
checkbox_layout.add_widget([Link])
checkbox_layout.add_widget(Label(text='Female'))
[Link] = CheckBox(active=False)
checkbox_layout.add_widget([Link])
checkbox_layout.add_widget(Label(text='Other'))
[Link] = CheckBox(active=False)
checkbox_layout.add_widget([Link])
self.add_widget(checkbox_layout)
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\[Link]
Step 3: Install Django: Install django by giving following command
30
Practical No
pip install django
Step 4: Start a project by following command-
django-admin startproject geeks_site
Step 5: Change directory to geeks_site
cd geeks_site
Step 6: Start the server- Start the server by typing following command in
cmd-
python [Link] runserver
Step 7: To check whether the server is running or not go to the web
browser and enter [Link] as URL.
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 2: Navigate to the Project Directory
cd hello_project
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python [Link] startapp hello_app
Step 4: Define a View
Open the [Link] file in the hello_app directory. Define a simple view
function that will handle the HTTP request and return a basic response.
[Link]
from [Link] import HttpResponse
def hello_world(request):
return HttpResponse("Hello, World!")
Step 5: Configure URLs
Create a [Link] file in the hello_app directory to define the URL patterns
for your app.
[Link]
from [Link] import path
from .views import
hello_world
urlpatterns = [ path('hello/', hello_world,
name='hello_world'), ]
Step 6: Include App URLs in Project URLs
33
Open the [Link] file in the hello_project directory and include the URLs of
the hello_app. [Link]
from [Link] import admin
from [Link] import path,
include
urlpatterns = [ path('admin/',
[Link]),
path('app/',
include('hello_app.urls')), ]
Step 7: Start the Django development server:
python [Link] 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 2: Navigate to the Project Directory
cd hello_project
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python [Link] startapp hello_app
34
Practical No
Step 4: Define a View
Open the [Link] file in the hello_app directory, and import the necessary
modules: [Link]
from [Link] import HttpResponse
from datetime import datetime
def current_datetime(request):
now = [Link]() formatted_datetime = [Link]("%Y-
%m-%d %H:%M:%S") return HttpResponse(f"Current Date and Time:
{formatted_datetime}")
Step 5: Configure URLs
Create a [Link] file in the hello_app directory and define the URL pattern
for the current_datetime view [Link]
from [Link] import path
from .views import
current_datetime urlpatterns = [
path('current_datetime/',
current_datetime,
name='current_datetime'),
]
Step 6: Include App URLs in Project URLs
Open the [Link] file in the hello_project directory and include the URLs of
the hello_app. [Link]
from [Link] import path
from .views import
current_datetime
urlpatterns = [ path('current_datetime/', current_datetime,
name='current_datetime'),
] from [Link] import
admin from [Link] import
path, include
urlpatterns = [ path('admin/',
[Link]),
path('app/',
include('hello_app.urls')), ]
Step 7: Start the Django development server:
35
python [Link] 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 2: Navigate to the Project Directory
cd hello_project
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python [Link] startapp hello_app
Step 4: Define a View
Create a view that calculates both the current time and the time after 10
hours [Link]
from [Link] import HttpResponse
from datetime import datetime,
timedelta
def time_info(request):
36
Practical No
now = [Link]() formatted_current_time =
[Link]("%Y-%m-%d %H:%M:%S")
time_after_10_hours = now + timedelta(hours=10)
formatted_time_after_10_hours = time_after_10_hours.strftime("%Y-%m-
%d
%H:%M:%S")
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)
Step 5: Configure URLs
Create a [Link] file in the hello_app directory and and add a dynamic URL
pattern for the time_info view [Link]
from [Link] import HttpResponse
from datetime import datetime,
timedelta
def time_info(request):
now = [Link]() formatted_current_time =
[Link]("%Y-%m-%d %H:%M:%S")
time_after_10_hours = now + timedelta(hours=10)
formatted_time_after_10_hours = time_after_10_hours.strftime("%Y-%m-
%d
%H:%M:%S")
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 [Link] import path
from .views import time_info
urlpatterns = [ path('time_info/', time_info,
name='time_info'), ]
Step 6: Include App URLs in Project URLs
Open the [Link] file in the hello_project directory and include the URLs of
the hello_app.
[Link]
from [Link] import HttpResponse
37
from datetime import datetime,
timedelta
def time_info(request):
now = [Link]() formatted_current_time =
[Link]("%Y-%m-%d %H:%M:%S")
time_after_10_hours = now + timedelta(hours=10)
formatted_time_after_10_hours = time_after_10_hours.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 [Link] import path
from .views import time_info
urlpatterns = [ path('time_info/', time_info,
name='time_info'),
] from [Link] import
admin from [Link] import
path, include
urlpatterns = [ path('admin/',
[Link]),
path('app/',
include('hello_app.urls')), ]
Step 7: Start the Django development server:
python [Link] 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 2: Navigate to the Project Directory
cd my_project
Step 3: Create a Django app within your project. This is where the
application-specific code will reside.
python [Link] startapp my_app
Step 4: Create a Templates Directory
Create a directory named templates inside your app directory
mkdir my_app/templates
Step 5: Create a Template File
Create a new file named [Link] inside the my_app/templates
directory [Link]
<!DOCTYPE html>
<html>
<head>
<title>Greeting Page</title>
</head>
<body>
<h1>Hello, {{ name }}!</h1>
</body>
</html>
Step 6: Define a View
Create a new file named [Link] inside the my_app directory
[Link]
from [Link] import
render def greet_user(request):
context = {
'name': 'Rajdeep',
40
} return render(request, '[Link]',
context)
Step 7: Configure URLs
Create a new file named [Link] inside the my_app directory
[Link]
from [Link] import path
from .views import greet_user
urlpatterns = [ path('greet/', greet_user,
name='greet_user'), ]
Step 8: Include App URLs in Project URLs
Open the [Link] file in the my_project directory and include the URLs of
the my_app. [Link]
from [Link] import admin
from [Link] import path,
include urlpatterns =
[ path('admin/', [Link]),
path('app/',
include('my_app.urls')),
]
Step 9: Start the Django development server:
python [Link] runserver
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 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 [Link] startapp new_app
Step 4: Define a Model in new_app/[Link]
Open the [Link] file inside the new_app directory and define a simple
model. [Link]
from [Link] import models
class MyModel([Link]):
name = [Link](max_length=100)
description = [Link]()
def __str__(self):
return [Link]
Step 4: Run Migrations
Run the following commands to apply the initial migrations
python [Link] makemigrations
python [Link] migrate
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 [Link] createsuperuser
This command will ask you to enter a username, email address, and
password for the superuser
Step 6: Register the Model in new_app/[Link]
from [Link] import
admin from .models import
MyModel
[Link](MyModel)
Step 7: Start the Django development server:
python [Link] runserver
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 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 [Link] startapp new_app
44
Step 4: Open [Link] file in project directory
[Link]
# Application definition
INSTALLED_APPS = [
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'new_app',
]
Step 5: In the new_app/[Link] file we define all objects called Models
[Link]
from [Link] import models
class MyModel([Link]):
name = [Link](max_length=100)
description = [Link]()
def __str__(self):
return [Link]
Step 6: Run Migrations
Run the following commands to apply the initial migrations
python [Link] makemigrations
python [Link] migrate
Step 7: Register the Model in new_app/[Link]
from [Link] import
admin from .models import
MyModel
[Link](MyModel)
Step 8: Start the Django development server:
python [Link] runserver
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 [Link] startapp new_app
Step 4: In the new_app/[Link] file we define all objects called Models
[Link]
from [Link] import models
class MyModel([Link]):
name =
[Link](max_length=100)
description = [Link]()
def __str__(self): return [Link]
Step 5: Run Migrations
Run the following commands to apply the initial migrations
python [Link] makemigrations
python [Link] migrate
Step 6: Register the Model in new_app/[Link]
from [Link] import
admin from .models import
MyModel
[Link](MyModel)
Step 7: Start the Django development server:
python [Link] runserver
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
b) Program to print star pattern
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