Call Girls in Pratap Nagar, 9953056974 Escort Service
ADLAB.pdf
1. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 1
ExpNo : 1
Date :__/__/____
Pass or Fail
Aim:
Write a program which accepts marks of 3 subjects (out of 100) of a student. Check whether the student
has passed or not. (He will not pass if he secure less than 40 for any subjects).If passed Find whether he
secure Distinction (Above or equal to 80%), First class (Above or equal to 60%), Second class (Above or
equal to 50%) or Third Class (Above or equal to 40%)
Covered Topics:
Python variables and Data types, control structures
Programme:
mark1 = int(input("Enter the first mark: "))
mark2 = int(input("Enter the second mark: "))
mark3 = int(input("Enter the third mark: "))
total = mark1 + mark2 + mark3
percentage = total*100/300
if (mark1<40 or mark2<40 or mark3<40):
print("Failed")
elif (percentage <50):
print("Passed with Third Class")
elif (percentage <60):
print("Passed with Second Class")
elif (percentage <80):
print("Passed with First Class")
else:
print("Passed with Distinction")
2. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 2
Output
1. Enter the first mark: 78
Enter the second mark: 98
Enter the third mark: 45
Passed with First Class
2. Enter the first mark: 54
Enter the second mark: 34
Enter the third mark: 78
Failed
RESULT:
The program is compiled, executed and the output is verified.
3. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 3
ExpNo : 2
Date :__/__/____
Math Game
Aim:
Write a math-game program that accepts a 3-digit integer from the user five times. On each input, if the
number is a multiple of 7, display the message “You Won” and stop the execution, otherwise show the
message “Try again”. If the user fails in all 5 attempts, show the message “Better luck next time” and stop.
Covered Topics:
Python variables and Data types, control structures, Loops
Programme:
print ("MATH-GAME")
for i in range(1,6):
num = int(input("Enter the 3-digit number: "))
if (num%7 == 0):
print ("Congratulations*******You Won")
exit()
if (i<5):
print ("Try again...")
else:
print ("Better luck next time")
exit()
Output
1. MATH-GAME
Enter the 3-digit number: 777
Congratulations*******You Won
2. MATH-GAME
Enter the 3-digit number: 234
Try again...
Enter the 3-digit number: 675
Try again...
Enter the 3-digit number: 323
Try again...
Enter the 3-digit number: 675
Try again...
4. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 4
Enter the 3-digit number: 342
Better luck next time
RESULT:
The program is compiled, executed and the output is verified.
5. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 5
ExpNo : 3
Date :__/__/____
List, Dictionary and Set
Aim:
Write a program to read the name of 5 employees into a list and their year of birth to another list in order.
Merge them into a single dictionary with the name as key and year of birth as value. Also display the years
of birth without duplicates.
Covered Topics:
Python variables and Data types, Loops, List, Dictionary, Set
Programme:
emp_name_list = list() # or simply emp_name_list = []
year_list = list()
emp_dict = dict() # or simply emp_dict = {}
year_set = set()
for i in range(0,5):
print ("Enter the name of employee "+ str(i+1) + ": ")
emp_name = input()
emp_name_list.append(emp_name)
print ("Enter the birth year of employee "+ str(i+1) + ": ")
year = int(input())
year_list.append(year)
for i in range(0,5):
emp_dict[emp_name_list[i]] = year_list[i]
year_set.add(year_list[i])
print ("nDictionary is: ")
print (emp_dict)
print ("nYear set is: ")
print (year_set)
6. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 6
Output
Enter the name of employee 1:
Rajeev
Enter the birth year of employee 1:
1990
Enter the name of employee 2:
Syam
Enter the birth year of employee 2:
1990
Enter the name of employee 3:
Nirmala
Enter the birth year of employee 3:
1992
Enter the name of employee 4:
Ram
Enter the birth year of employee 4:
1989
Enter the name of employee 5:
Sajith
Enter the birth year of employee 5:
1987
Dictionary is:
{'Rajeev': 1990, 'Syam': 1990, 'Nirmala': 1992, 'Ram': 1989, 'Sajith': 1987}
Year set is:
{1992, 1987, 1989, 1990}
RESULT:
The program is compiled, executed and the output is verified.
7. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 7
ExpNo : 4
Date :__/__/____
Class and Object
Aim:
Write a program to read the name and number of tyres of three vehicles and display the summary using
class.
Covered Topics:
Python variables and Data types, class, objects
Programme:
class Vehicle:
name = ""
tyre = 0
veh1 = Vehicle()
print ("Enter the name of Vehicle : ")
veh1.name = input()
print ("Enter the Number of Tyres : ")
veh1.tyre = input()
veh2 = Vehicle()
print ("Enter the name of Vehicle : ")
veh2.name = input()
print ("Enter the Number of Tyres : ")
veh2.tyre = input()
veh3 = Vehicle()
print ("Enter the name of Vehicle : ")
veh3.name = input()
print ("Enter the Number of Tyres : ")
veh3.tyre = input()
print ("nnVEHICLE SUMMARYn***************")
print(f"{veh1.name} has {veh1.tyre} tyres")
print(f"{veh2.name} has {veh2.tyre} tyres")
print(f"{veh3.name} has {veh3.tyre} tyres")
8. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 8
Output
Enter the name of Vehicle :
Bus
Enter the Number of Tyres :
6
Enter the name of Vehicle :
car
Enter the Number of Tyres :
4
Enter the name of Vehicle :
bike
Enter the Number of Tyres :
2
VEHICLE SUMMARY
***************
Bus has 6 tyres
car has 4 tyres
bike has 2 tyres
RESULT:
The program is compiled, executed and the output is verified.
9. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 9
ExpNo : 5
Date :__/__/____
Python and django framework installation
Aim:
To Install and familiarize of Python and Django framework.
Proceedure:
Django is a Python framework that makes it easier to create web sites using Python. Django takes care of
the difficult stuff so that you can concentrate on building your web applications.Django emphasizes
reusability of components, also referred to as DRY (Don't Repeat Yourself), and comes with ready-to-use
features like login system, database connection and CRUD operations (Create Read Update Delete).
Django follows the MVT design pattern (Model View Template).
Model - The data you want to present, usually data from a database.
View - A request handler that returns the relevant template and content - based on the request from
the user.
Template - A text file (like an HTML file) containing the layout of the web page, with logic on
how to display the data.
Installation of Python Django Frame work
1. Install Python
Django Requires Python.To check if your system has Python installed, run this command in the
command prompt
python –version
If Python is installed, you will get a result with the version number, like this
Python 3.9.2
If you find that you do not have Python installed on your computer, then you can download it for
free from the following website: https://www.python.org
10. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 10
Download the file and install python.
2. Install a Code Editor
There are many code editors available for programming with Python. VSCode is one of the most
used code editor for python and Django combinations.
You can download it for free from the following website: https://code.visualstudio.com
You can select the operating system and download the installation file and double click to install.
After Installing Start vscode
Now the following window opens. Then select extensions.
VS Code extensions let you add languages, debuggers, and tools to your installation to support
your development workflow. Search python extension and install. Python extension helps to edit
11. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 11
your code with auto-completion, code navigation, syntax checking and more. Then install django
extension.
The create a folder and drag it to the vscode.
Then you can see the folder in the explorer section of vscode.
3. Create a virtual environment
The virtual environment is an environment which is used by Django to execute an application. It is
recommended to create and execute a Django application in a separate environment. Python
provides a tool virtualenv to create an isolated Python environment.
Select the terminal and new terminal. Then the terminal opens.
Then type the command and press enter.
12. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 12
python -m venv djangoenv
The djangoenv is the environment name that we given. Then the virtual environment name is
shown under the folder name in explorer.
Then activate the virtual environment by the following command
djangoenvscriptsactivate
Then the terminal shown like this
4. Installing Django
Install the django environment to the virtual environment that we create.
Connect to the internet and type the following command and enter
pip install django
After Successful installation we can see the django package under the environment that we
Create.
Create Django project using the command
django-admin startproject proj_name
Enter into the project directory
cd proj_name
13. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 13
Migrations are Django‟s way of propagating changes you make to your models (adding a field,
deleting a model, etc.) into your database schema.
migration is run through the following command for a Django project.
Python manage.py migrate
To run the Django development server, type the command
python manage.py runserver
in your terminal of the Django project and hit enter. If everything is okay with your project,
Django will start running the server at localhost port 8000 (127.0. 0.1:8000) and then you have to
navigate to that link in your browser.
RESULT:
Installed Python and Django framework successfully.
14. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 14
ExpNo : 6
Date :__/__/____
Django URL and Views
Aim:
Develop a home page and display the page and different displays according to the URL that we given.
Proceedure:
Django project is the whole website. A Django application is a Python package that is specifically
intended for use in a Django project. An application may use common Django conventions, such as
having models , tests , urls , and views submodules.A django project may contains any number of apps.
Create the project
django-admin startproject proj1
Enter in to the directory
cd proj1
Create app
Python manage,py startapp home
Manage the app as part of the project
Take settings.py of project. Add the app in the installed apps section. Then save.
15. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 15
Django follows the MVT design pattern. The MVT(Model View Template) is a software design pattern.
Django work as follows.
Gets user requests by URL and responds back by map that route to call specified view function.To handle
URL,django.urls module was used by the framework.
Insert a URL in projects urls.py and forward it to apps urls.py and map it to the apps views,py.
16. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 16
Take urls.py of project.Set the path of app url.Then save
Then create urls.py file in app directory and copy the contents of projects urls.py in to apps urls.py.
17. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 17
Delete the admin path and insert the views function.
Here we use three views.‟ „ means root .
Define all functions in the views.py of app.
18. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 18
Run the server. Open a web browser and enter the address http:://127.0.0.1:8000.Then we can see the web
page define in index function.
http:://127.0.0.1:8000/about
19. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 19
http:://127.0.0.1:8000/contacts
RESULT:
Successfully created the web page.
20. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 20
ExpNo : 7
Date :__/__/____
Login Page Creation
Aim:
Create a simple login page with username and password using the Django framework.
Proceedure:
Here we use django templates. A template describes an html page and contains variables which are
swapped out for content which makes them dynamic. Go to the base folder and create a new folder
named templates.
Here we create the html file index.html.
21. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 21
In the code window type ht then the menu contains html5-boilerplate will appear.Select it.
HTML basic structure will be displayed
22. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 22
The type HTML code to create the login form inside <head>..</head> and <body>..</body> tags. Save the
file.
Inside < head> tags
<style>
Body {
font-family: Calibri, Helvetica, sans-serif;
background-color: #586876 ;
}
.container {
padding: 25px;
background-color: #1E2C42;
color: white;
}
input[type=text], input[type=password] {
width: 50%;
margin: 8px 0;
padding: 12px 20px;
display: inline-block;
border: 2px solid green;
box-sizing: border-box;
}
button {
background-color: #586876;
color: white;
width: 25%;
padding: 15px;
margin: 10px 0px;
border: none;
cursor: pointer;
}
</style>
Inside <body> tags
<form> <br><br>
<div class="container">
<center>
<h1> Student Login Form </h1>
<label><h3>Username </h3></label>
23. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 23
<input type="text" placeholder="Enter Username" ><br>
<label><h3>Password <h3> </label>
<input type="password" placeholder="Enter Password" ><br>
<button type="submit">Login</button> </center>
</div>
</form>
Set the urls.py of project and urls.py of app as in the earlier application
24. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 24
Go to the view.py of app. Then make the template as response. Save the file.
Then add the templates folder in the project settings. Open settings.py of project .Then go to teplates
part and add our directory templates to „DIRS‟ and save the file.
Run the server and see the result in the browser by giving the address
http:://127.0.0.1:8000
25. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 25
RESULT:
Successfully created the login page.
26. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 26
ExpNo : 8
Date :__/__/____
User registration and Login
Aim:
Create a user registration and login form. If the login is successful display message in another page.
Proceedure:
Create a project named proj1
django-admin startproject Proj1
Create an App inside the project
cd proj1
python manage.py startapp login
Projects settings.py
Projects urls.py
from django.conf.urls import include, url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^$', views.index_redirect, name='index_redirect'),
url(r'^web/', include('login.urls')),
27. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 27
url(r'^admin/', admin.site.urls),
]
Projects views.py
from django.shortcuts import redirect
from . import views
def index_redirect(request):
return redirect('/web/')
Apps urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^login/$', views.login, name='login'),
url(r'^home/$', views.home, name='home'),
]
Apps views.py
from django.shortcuts import render, redirect, HttpResponseRedirect
from .models import Member
# Create your views here.
def index(request):
if request.method == 'POST':
member = Member(username=request.POST['username'],
password=request.POST['password'], firstname=request.POST['firstname'],
lastname=request.POST['lastname'])
member.save()
return redirect('/')
else:
return render(request, 'index.html')
def login(request):
return render(request, 'login.html')
def home(request):
if request.method == 'POST':
if Member.objects.filter(username=request.POST['username'],
password=request.POST['password']).exists():
28. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 28
member = Member.objects.get(username=request.POST['username'],
password=request.POST['password'])
return render(request, 'home.html', {'member': member})
else:
context = {'msg': 'Invalid username or password'}
return render(request, 'login.html', context)
Apps models.py
from django.db import models
# Create your models here.
class Member(models.Model):
firstname=models.CharField(max_length=30)
lastname=models.CharField(max_length=30)
username=models.CharField(max_length=30)
password=models.CharField(max_length=12)
def __str__(self):
return self.firstname + " " + self.lastname
Create a folder templates in app directory and create these html files
Home.html
<style>
body {
background-color: #76CAD1;
}
</style>
{% block body %}
<h3 class="text-primary"><center> Login Successfull</h3></center>
<Font color="D64C11"> <center> <h2>Welcome</h2>
<h1> <b> {{ member.firstname }}</h1><b></font>
{% endblock %}
Index.html
<style>
body {
background-color: #76CAD1;
}
30. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 30
<b>
<form method="POST" action="{% url 'home' %}">
{% csrf_token %}
<div class="col-md-8">
<div class="form-group">
<h3 class="text-primary"><center> Login</h3></center>
<label for="username">Username</label>
<input type="text" name="username" class="form-control"
required="required"/>
</div><br>
<div class="form-group">
<label for="password">Password </label>
<input type="password" name="password" class="form-control"
required="required"/>
</div>
<center><label class="text-danger">{{ msg }}</label></center>
<br />
<div class="form-group">
<button class="btn btn-primary form-control"><span class="glyphicon
glyphicon-log-in"></span> Login</button>
</div><br><br>
<div class="col-md-2">
<h2> <a href="{% url 'index' %}">Signup</a>
</div>
</div>
</form>
{% endblock %}
Make the migrations
python manage.py makemigrations
python manage.py migrate
Run Development Server
python manage.py runserver
View the Result
open the browser and take http://127.0.0.1:8000/
31. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 31
Create a user and login with that user.
We get the home page
RESULT:
Successfully created the page.
32. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 32
ExpNo : 9
Date :__/__/____
Department Website
Aim:
Create a website for the department..
Proceedure:
Create a project named web.
django-admin startproject web
Create an App inside the project
cd web
python manage.py startapp dept
settings.py
web urls.py
from django.contrib import admin
from django.urls import path,include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('dept.urls'))
]+ static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
33. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 33
MEDIA_URL: Similar to the STATIC_URL , this is the URL where users can access media files.
MEDIA_ROOT: The absolute path to the directory where your Django application will serve your media
files from.
Dept urls.py
from django.contrib import admin
from django.urls import path,include
from . import views
urlpatterns = [
path('', views.homes,name='homes'),
path('vision',views.vision,name='vision'),
path('staff',views.staff,name='staff'),
path('contact',views.contact,name='contact'),
path('gallery',views.gallery,name='gallery'),
path('placement',views.placement,name='placement'),
]
Views.py
from django.shortcuts import render
from .models import depthome,deptvision,deptstaff,deptplace,depgallery,deptcontact
# Create your views here.
def homes(request):
dict_dept={
'dept':depthome.objects.all()
}
return render(request,'home.html',dict_dept)
def vision(request):
dict_vis={
'vis':deptvision.objects.all()
}
return render(request,'vision.html',dict_vis)
def staff(request):
dict_staffs={
'staffs':deptstaff.objects.all()
}
return render(request,'staff.html',dict_staffs)
def contact(request):
dict_cont={
'cont':deptcontact.objects.all()
34. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 34
}
return render(request,'contact.html',dict_cont)
def gallery(request):
dict_gal={
'gal':depgallery.objects.all()
}
return render(request,'gallery.html',dict_gal)
def placement(request):
dict_place={
'place':deptplace.objects.all()
}
return render(request,'placement.html',dict_place)
models.py
from django.db import models
class depthome(models.Model):
dep_name=models.CharField(max_length=100)
dep_description=models.TextField()
dep_image=models.ImageField(upload_to='dep')
class deptvision(models.Model):
vis_image=models.ImageField(upload_to='dep')
vis_description=models.TextField()
class deptstaff(models.Model):
staff_name=models.CharField(max_length=100)
staff_description=models.TextField()
staff_image=models.ImageField(upload_to='dep')
class deptplace(models.Model):
place_name=models.CharField(max_length=100)
place_description=models.TextField()
place_image=models.ImageField(upload_to='dep')
class depgallery(models.Model):
gal_name=models.CharField(max_length=100)
gal_image=models.ImageField(upload_to='dep')
class deptcontact(models.Model):
cont_name=models.CharField(max_length=100)
cont_address=models.TextField()
cont_email=models.TextField()
35. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 35
cont_phone=models.TextField()
The Python Imaging Library adds image processing capabilities to your Python interpreter.This library
provides extensive file format support, an efficient internal representation, and fairly powerful image
processing capabilities.The core image library is designed for fast access to data stored in a few basic pixel
formats. It should provide a solid foundation for a general image processing tool.Install pillow.
python -m pip install Pillow
admin.py
from django.contrib import admin
from .models import depthome,deptvision,deptstaff,deptplace,depgallery,deptcontact
# Register your models here.
admin.site.register(depthome)
admin.site.register(deptvision)
admin.site.register(deptstaff)
admin.site.register(deptplace)
admin.site.register(depgallery)
admin.site.register(deptcontact)
create the folder templates and create the html files.
43. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 43
We can manage the data in the website by using admin panel.
Create a superuser
python manage.py createsuperuser
Then enter the Username of your choice and press enter.
Username: srishti
Then enter the Email address and press enter.(It can be left blank)
Email address: example@gmail.com
Next, enter the Password in-front of the Password field and press enter.Enter a strong
password so as to keep it secure.
Password: ******
Then again enter the same Password for confirmation.
Password(again): ******
Superuser created successfully if above fields are entered correctly.
Enter the URL http://127.0.0.1:8000/admin in browser
44. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 44
Enter the username and password
Then the admin panel appears. Here we can see all the models that we create
45. Application Development Lab S4 CT
Prepared By
Sreekanth M G ,GPTC Nedumkandam Page. 45
We can add data to any models by using add button
RESULT:
Successfully created the web site of department.