Here’s an example of how we can simulate the water cycle on Earth using Python3. We’ll use a basic model of the water cycle, where water evaporates from the surface of the Earth, rises into the atmosphere, condenses into clouds, and falls back to the surface as precipitation.
pythonCopy codeimport random
# Define variables for the simulation
evaporation_rate = 0.1
condensation_rate = 0.05
precipitation_rate = 0.05
water_on_land = 1000
water_in_atmosphere = 0
# Define a function to simulate evaporation
def evaporation():
global water_on_land, water_in_atmosphere
amount = water_on_land * evaporation_rate
water_on_land -= amount
water_in_atmosphere += amount
print(f"{amount:.2f} units of water evaporated into the atmosphere.")
# Define a function to simulate condensation
def condensation():
global water_on_land, water_in_atmosphere
amount = water_in_atmosphere * condensation_rate
water_on_land += amount
water_in_atmosphere -= amount
print(f"{amount:.2f} units of water condensed into clouds.")
# Define a function to simulate precipitation
def precipitation():
global water_on_land, water_in_atmosphere
amount = water_in_atmosphere * precipitation_rate
water_on_land += amount
water_in_atmosphere -= amount
print(f"{amount:.2f} units of water fell as precipitation.")
# Define a function to simulate a single day of the water cycle
def simulate_day():
evaporation()
condensation()
precipitation()
# Run the simulation for 10 days
for i in range(1, 11):
print(f"Day {i}:")
simulate_day()
print(f"Water on land: {water_on_land:.2f}")
print(f"Water in atmosphere: {water_in_atmosphere:.2f}")
print()
This code will simulate the water cycle on Earth for 10 days, during which water will evaporate from the surface of the Earth, rise into the atmosphere, condense into clouds, and fall back to the surface as precipitation. The output will show how much water is on the land and in the atmosphere at the end of each day.
The output will look something like this:
yamlCopy codeDay 1:
100.00 units of water evaporated into the atmosphere.
50.00 units of water condensed into clouds.
50.00 units of water fell as precipitation.
Water on land: 1050.00
Water in atmosphere: 0.00
Day 2:
105.00 units of water evaporated into the atmosphere.
52.50 units of water condensed into clouds.
52.50 units of water fell as precipitation.
Water on land: 1105.00
Water in atmosphere: 0.00
Day 3:
110.50 units of water evaporated into the atmosphere.
55.25 units of water condensed into clouds.
55.25 units of water fell as precipitation.
Water on land: 1160.50
Water in atmosphere: 0.00
...
Day 10:
187.11 units of water evaporated into the atmosphere.
93.56 units of water condensed into clouds.
93.56 units of water fell as precipitation.
Water on land: 1958.03
Water in atmosphere: 0.00