SciPy includes a constants
module, which contains a large number of physical and mathematical constants.
Example:
from scipy import constants print("Speed of light in vacuum:", constants.c, "m/s") print("Gravitational constant:", constants.G, "m^3 kg^-1 s^-2") print("Pi:", constants.pi)
Here, we import constants from SciPy and print the values of the speed of light, the gravitational constant, and pi.
Binary is typically used for representing numbers in base-2. Let's convert a decimal number to binary:
decimal_number = 10 binary_number = bin(decimal_number) print("Binary of 10:", binary_number)
from scipy.constants import kilo mass = 5 * kilo # 5 kilograms print("Mass:", mass, "grams")
from scipy.constants import pi angle_in_degrees = 90 angle_in_radians = angle_in_degrees * (pi / 180) # Convert degrees to radians print("Angle in radians:", angle_in_radians)
from scipy.constants import minute time_in_minutes = 5 time_in_seconds = time_in_minutes * minute # Convert minutes to seconds print("Time in seconds:", time_in_seconds)
from scipy.constants import foot length_in_feet = 10 length_in_meters = length_in_feet * foot # Convert feet to meters print("Length in meters:", length_in_meters)
from scipy.constants import atmosphere pressure_in_atm = 1 pressure_in_pascals = pressure_in_atm * atmosphere # Convert atmosphere to pascals print("Pressure in pascals:", pressure_in_pascals)
from scipy.constants import liter volume_in_liters = 3 volume_in_cubic_meters = volume_in_liters * liter # Convert liters to cubic meters print("Volume in cubic meters:", volume_in_cubic_meters)
from scipy.constants import speed_of_light speed = 0.1 * speed_of_light # 10% of the speed of light print("Speed:", speed, "meters per second")
from scipy.constants import zero_Celsius temperature_in_Celsius = 25 temperature_in_Kelvin = zero_Celsius + temperature_in_Celsius # Convert Celsius to Kelvin print("Temperature in Kelvin:", temperature_in_Kelvin)
from scipy.constants import calorie energy_in_calories = 10 energy_in_joules = energy_in_calories * calorie # Convert calories to joules print("Energy in joules:", energy_in_joules)
from scipy.constants import horsepower power_in_hp = 2 power_in_watts = power_in_hp * horsepower # Convert horsepower to watts print("Power in watts:", power_in_watts)
from scipy.constants import kilogram, g mass = 10 * kilogram # 10 kilograms force = mass * g # Calculate force in newtons using F = m * g print("Force in newtons:", force)