THIS SITE IS A GAME DEVOLOPING AND SOFTWARE MAKING SITE
MAKE SOFTWARE AND SELL IT
import requests
def get_weather(city, api_key):
"""
Fetches weather data for a specified city.
"""
base_url = "http://api.openweathermap.org/data/2.5/weather"
params = {"q": city, "appid": api_key, "units": "metric"}
try:
response = requests.get(base_url, params=params)
response.raise_for_status()
data = response.json()
return {
"city": data["name"],
"temperature": data["main"]["temp"],
"humidity": data["main"]["humidity"],
"description": data["weather"][0]["description"],
}
except requests.exceptions.RequestException as e:
return {"error": f"Network error: {e}"}
except KeyError:
return {"error": "Invalid response from weather API."}
if __name__ == "__main__":
API_KEY = "your_api_key_here" # Replace with your API key
city_name = input("Enter the name of the city: ")
weather_info = get_weather(city_name, API_KEY)
if "error" in weather_info:
print(weather_info["error"])
else:
print(f"Weather in {weather_info['city']}:")
print(f"Temperature: {weather_info['temperature']}°C")
print(f"Humidity: {weather_info['humidity']}%")
print(f"Description: {weather_info['description']}")
THIS IS A PYTHON CODE FOR WEATHER DETECT APP
import pygame
import time
import random
# Initialize pygame
pygame.init()
# Screen dimensions
WIDTH, HEIGHT = 600, 400
BLOCK_SIZE = 20
SNAKE_SPEED = 15
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Initialize the screen
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Snake Game")
# Clock for controlling game speed
clock = pygame.time.Clock()
# Font for text
font_style = pygame.font.SysFont("bahnschrift", 25)
score_font = pygame.font.SysFont("comicsansms", 20)
def display_score(score):
value = score_font.render(f"Your Score: {score}", True, BLUE)
screen.blit(value, [10, 10])
def draw_snake(block_size, snake_list):
for block in snake_list:
pygame.draw.rect(screen, GREEN, [block[0], block[1], block_size, block_size])
def message(msg, color):
msg_surface = font_style.render(msg, True, color)
screen.blit(msg_surface, [WIDTH / 6, HEIGHT / 3])
def game_loop():
# Snake starting position and direction
game_over = False
game_close = False
x, y = WIDTH // 2, HEIGHT // 2
x_change, y_change = 0, 0
snake_list = []
length_of_snake = 1
# Food position
food_x = round(random.randrange(0, WIDTH - BLOCK_SIZE) / BLOCK_SIZE) * BLOCK_SIZE
food_y = round(random.randrange(0, HEIGHT - BLOCK_SIZE) / BLOCK_SIZE) * BLOCK_SIZE
while not game_over:
while game_close:
screen.fill(WHITE)
message("You Lost! Press Q-Quit or C-Play Again", RED)
display_score(length_of_snake - 1)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game_over = True
game_close = False
if event.key == pygame.K_c:
game_loop()
# Event handling for movement
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT and x_change == 0:
x_change = -BLOCK_SIZE
y_change = 0
elif event.key == pygame.K_RIGHT and x_change == 0:
x_change = BLOCK_SIZE
y_change = 0
elif event.key == pygame.K_UP and y_change == 0:
y_change = -BLOCK_SIZE
x_change = 0
elif event.key == pygame.K_DOWN and y_change == 0:
y_change = BLOCK_SIZE
x_change = 0
# Boundaries check
if x >= WIDTH or x < 0 or y >= HEIGHT or y < 0:
game_close = True
# Update snake head position
x += x_change
y += y_change
screen.fill(BLACK)
# Draw food
pygame.draw.rect(screen, RED, [food_x, food_y, BLOCK_SIZE, BLOCK_SIZE])
# Update snake
snake_head = [x, y]
snake_list.append(snake_head)
if len(snake_list) > length_of_snake:
del snake_list[0]
# Check for collision with itself
for block in snake_list[:-1]:
if block == snake_head:
game_close = True
draw_snake(BLOCK_SIZE, snake_list)
display_score(length_of_snake - 1)
# Check if food is eaten
if x == food_x and y == food_y:
food_x = round(random.randrange(0, WIDTH - BLOCK_SIZE) / BLOCK_SIZE) * BLOCK_SIZE
food_y = round(random.randrange(0, HEIGHT - BLOCK_SIZE) / BLOCK_SIZE) * BLOCK_SIZE
length_of_snake += 1 # Snake grows
pygame.display.update()
clock.tick(SNAKE_SPEED)
pygame.quit()
quit()
# Run the game
game_loop()
CODE FOR SNAKE GAME