Article Python Fundamentals
Python Functions for Beginners
Learn to write your own Python functions, from your first def to return values, default parameters and scope, with runnable examples, common mistakes and six practice projects.
Showing 1–10 of 12
Article Python Fundamentals
Learn to write your own Python functions, from your first def to return values, default parameters and scope, with runnable examples, common mistakes and six practice projects.
Article Mini projects
…let's break down our solution step by step: Step 1: Define Constants and Data First, let's specify what we know: import numpy as np # Gravitational constant - always the same in the universe G =…
Article Mini projects
…that class: import sqlite3 class CosmicHealthTracker: def __init__(self): #let's create database first self.create_database() def create_database(self): conn = sqlite3.connect('space_station.db')…
Article Mini projects
…read in reverse order, give you the base-6 number. def decimal_to_base6(decimal_number): if decimal_number == 0: return "0" digits = [] # We'll collect remainders here number = decimal_number while…
Article Mini projects
…handle them. Functions for converting temperatures Let's define 2 functions necessary for our calculations. These will be the celsius_to_kelvin and fahrenheit_to_kelvin functions: def…
Article Mini projects
…planets and another to calculate their orbital paths: def create_planet(color, size): planet = turtle.Turtle() planet.shape("circle") planet.color(color) planet.shapesize(size) planet.penup() return…
Article Mini projects
…write a function that randomly selects our destination: def select_random_destination(): # Choose a random planet destination = random.choice(list(planets.keys())) # Get planet details planet_info =…
Article Mini projects
…dictionary where you have a word (the key) and its definition (the value). In our program, we use a dictionary to store planets (keys) and their corresponding surface gravities (values). This allows…
Article Python Fundamentals
…readings temperature = 21 pressure = 101.3 oxygen = 98 # Default separation (space) print("Temperature:", temperature, "Pressure:", pressure, "Oxygen:", oxygen) # Output: Temperature: 21 Pressure…
Article Mini projects
…"""The Hail Mary's original dispenser - easily hackable""" def __init__(self): self.dose_history = [] self.minimum_interval = timedelta(hours=3) self.max_daily_doses = 6 def request_dose(self…