Python Programming
Python Programming
Parameters:
weight (float): Weight in kilograms
height (float): Height in meters
Returns:
float: Calculated BMI
"""
bmi = weight / (height ** 2)
return bmi
def bmi_category(bmi):
"""
Determine the BMI category based on the BMI
value.
Parameters:
bmi (float): The calculated BMI
Returns:
str: The category of BMI
"""
if bmi < 18.5:
return "Underweight"
elif 18.5 <= bmi < 24.9:
return "Normal weight"
elif 25 <= bmi < 29.9:
return "Overweight"
else:
return "Obesity"
def main():
"""
Main function to execute the BMI calculator.
"""
try:
weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in meters:
"))
except ValueError:
print("Please enter valid numerical values for
weight and height.")
if __name__ == "__main__":
main()
OUTPUT:
Enter your weight in kg: 52
Enter your height in meters: 1.64
Your BMI is: 19.33
You are classified as: Normal weight
Parameters:
length (int): Length of the password
use_uppercase (bool): Whether to include
uppercase letters
use_digits (bool): Whether to include digits
use_special_chars (bool): Whether to include
special characters
Returns:
str: Generated password
"""
# Base characters for the password
characters = string.ascii_lowercase # Always
include lowercase letters
if use_uppercase:
characters += string.ascii_uppercase
if use_digits:
characters += string.digits
if use_special_chars:
characters += string.punctuation
def main():
print("Welcome to the Simple Password
Generator!")
try:
length = int(input("Enter the desired length of the
password: "))
use_uppercase = input("Include uppercase
letters? (y/n): ").lower() == 'y'
use_digits = input("Include digits? (y/n):
").lower() == 'y'
use_special_chars = input("Include special
characters? (y/n): ").lower() == 'y'
password = generate_password(length,
use_uppercase, use_digits, use_special_chars)
print(f"Generated Password: {password}")
except ValueError:
print("Please enter a valid number for the
length.")
if __name__ == "__main__":
main()
OUTPUT:
Welcome to the Simple Password Generator!
Enter the desired length of the password: 7
Include uppercase letters? (y/n): y
Include digits? (y/n): y
Include special characters? (y/n): y
Generated Password: ]S6K3|z
CODE:
Index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Weather App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Weather App</h1>
<select id="citySelect">
<option value="">Select a city</option>
<option value="New York">New York</option>
<option value="London">London</option>
<option value="Tokyo">Tokyo</option>
<option value="Paris">Paris</option>
<option value="Sydney">Sydney</option>
</select>
<input type="text" id="cityInput" placeholder="Or
enter city name">
<button id="searchButton">Get Weather</button>
<div class="weather-info">
<h2 id="location"></h2>
<p id="temperature"></p>
<p id="description"></p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Style.css:
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.container {
max-width: 400px;
margin: 0 auto;
text-align: center;
padding: 20px;
background-color: rgba(255, 255, 255, 0.8);
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
input[type="text"], select {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
background-color: #007BFF;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.weather-info {
margin-top: 20px;
}
Script.jss:
const apiKey = 'YOUR_API_KEY'; // Replace with your
OpenWeatherMap API key
const apiUrl =
'https://api.openweathermap.org/data/2.5/weather';
document.getElementById('searchButton').addEventListener
('click', () => {
const cityInput =
document.getElementById('cityInput').value;
const citySelect =
document.getElementById('citySelect').value;
const city = cityInput || citySelect; // Use input or
selected city
if (city) {
fetchWeather(city);
}
});
function fetchWeather(city) {
const url = `${apiUrl}?q=${city}&appid=$
{apiKey}&units=metric`;
fetch(url)
.then(response => response.json())
.then(data => {
if (data.cod === 200) {
displayWeather(data);
} else {
alert('City not found. Please try again.');
}
})
.catch(error => {
console.error('Error fetching weather data:', error);
});
}
function displayWeather(data) {
document.getElementById('location').textContent = `$
{data.name}, ${data.sys.country}`;
document.getElementById('temperature').textContent =
`${Math.round(data.main.temp)}°C`;
document.getElementById('description').textContent =
data.weather[0].description;
}