One and one and one is …

news
code
analysis
Author

George Girton

Published

May 9, 2022

This is a post with executable code.

First, some code in R. When I first ran it in Visual Studio Code, I got an offer to install the R extensions (accepted).

Code
1 + 1 + 1
[1] 3
Code
quadrillion = 1000 * 1000 * 1000* 1000
erm_radius <- 6372795.477598   #Earth radius in meters
eartharea <- 4 * pi * erm_radius * erm_radius
print(eartharea/quadrillion)
[1] 510.352

Then, some code in python. When I first ran it in RStudio, I got an error message that looked like this:

(picture of an error message meaning: You didn’t install reticulate)

after that, I did this:

install-packages("reticulate")

and everything worked just fine

Code
from decimal import *

PI= Decimal('3.1415926535897931')
RADIUS= Decimal('6372795.477598')   #Earth radius in meters
RADIUS1 = RADIUS+1

# Formula for volume is four-thirds pi R cubed

m1 = 4 * PI / 3
V= m1 * RADIUS * RADIUS * RADIUS
V1= m1 * RADIUS1 * RADIUS1 * RADIUS1

print (V ," cubic meters")
1084122984296576747840.498564  cubic meters
Code
area = V1-V
print (area , " square meters")
510352085623125.659716  square meters
Code
quadrillion = 1000 * 1000 * 1000 * 1000 
print(quadrillion)
1000000000000
Code
print (area/quadrillion, "quadrillion square meters")
510.352085623125659716 quadrillion square meters

— all photos Copyright © 2022-2024 George D Girton all rights reserved