Py 12
Py 12
views.py
from django.shortcuts import render
def home(request):
if request.GET.get("radius"):
radius = float(request.GET.get("radius"))
pi = 3.14
area = pi * radius * radius
circum = 2 * pi * radius
msg = "Area = " + str(area) + " | Circumference = " + str(circum) # Added a space and "|"
separator
return render(request, "home.html", {"msg": msg})
else:
return render(request, "home.html")
HTML Page :
<!DOCTYPE html>
<html>
<head>
<title>Area & Circumference Finder</title>
<style>
body {
background-color: cyan;
font-family: Times New Roman;
}
h1 {
background-color: black;
color: white;
width: 50%;
border-radius: 30px;
text-align: center;
padding: 10px;
margin: 20px auto;
}
form {
text-align: center;
margin: 0 auto;
}
input[type="number"] {
font-size: 20px;
padding: 5px;
margin: 5px;
border-radius: 5px;
border: 1px solid #ccc;
}
input[type="submit"] {
font-size: 20px;
padding: 10px 20px;
margin: 10px;
border-radius: 5px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.result {
text-align: center;
margin-top: 20px;
font-size: 24px;
color: blue;
}
</style>
</head>
<body>
<h1>Area & Circumference Finder</h1>
<form>
<input type="number" step="any" name="radius" placeholder="Enter radius" required
min="0.1" />
<br><br>
<input type="submit" value="Find Area and Circumference" />
</form>
<div class="result">{{ msg }}</div>
</body>
</html>
************************************B444**********************************
Output: