This tutorials helps you to create a simple formula, in this case, it will sum two positive numbers.
rit math sum numbers
.This formula must have (at least) two input parameters. See below:
RIT_NUMBER_ONE
).RIT_NUMBER_TWO
).Search for the config.json
file of your formula and replace it the inputs
field for the block below:
{
"label": "Number one : ",
"name": "rit_number_one",
"type": "text"
},
{
"label": "Number two : ",
"name": "rit_number_two",
"type": "text"
}
]
Follow the steps below to create your formula:
Search for the main
file of tour formula and extract all the inputs before using them to call your formula’s method. See some code example below:
import os
from formula import formula
number_one = int(os.environ.get("RIT_NUMBER_ONE"))
number_two = int(os.environ.get("RIT_NUMBER_TWO"))
formula.run(number_one, number_two)
package com.ritchie;
import com.ritchie.formula.Formula;
public class Main {
public static void main(String[] args) {
String numberOne = System.getenv("RIT_NUMBER_ONE");
String numberTwo = System.getenv("RIT_NUMBER_TWO");
Formula formula = new Formula(Integer.valueOf(numberOne), Integer.valueOf(numberTwo));
System.out.println(formula.run());
}
}
package main
import (
"formula/pkg/formula"
"os"
"strconv"
)
func main() {
numberOne, _ := strconv.Atoi(os.Getenv("RIT_NUMBER_ONE"))
numberTwo, _ := strconv.Atoi(os.Getenv("RIT_NUMBER_TWO"))
formula.Formula{
NumberOne: numberOne,
NumberTwo: numberTwo,
}.Run()
}
const run = require("./formula/formula")
const NUMBER_ONE = parseInt(process.env.RIT_NUMBER_ONE)
const NUMBER_TWO = parseInt(process.env.RIT_NUMBER_TWO)
run(NUMBER_ONE, NUMBER_TWO)
Warning: Here is where the conversion from STRING to INT happens, because there is no native INT type in the config.json
file.
main.*
nomenclature for most languages, except Node that it calls index.js
.Search for the formula
file of your formula and implement the method performing the operation of your automation. See some code examples:
def run(number_one, number_two):
sum = number_one + number_two
print("The sum is", sum)
package com.ritchie.formula;
public class Formula {
private Integer numberOne;
private Integer numberTwo;
public String run() {
Integer sum = numberOne + numberTwo;
return String.format("The sum is %s", sum);
}
public Formula(Integer numberOne, Integer numberTwo) {
this.numberOne = numberOne;
this.numberTwo = numberTwo;
}
public Integer getNumberOne() {
return numberOne;
}
public void setNumberOne(Integer numberOne) {
this.numberOne = numberOne;
}
public Integer getNumberTwo() {
return numberTwo;
}
public void setNumberTwo(Integer numberTwo) {
this.numberTwo = numberTwo;
}
}
package formula
import (
"fmt"
)
type Formula struct {
NumberOne int
NumberTwo int
}
func (f Formula) Run() {
sum := f.NumberOne + f.NumberTwo
fmt.Println("The sum is", sum)
}
function Run(numberOne, numberTwo) {
var sum = numberOne + numberTwo
console.log("The sum is " + sum)
}
const formula = Run
module.exports = formula
~ rit math sum numbers
? Number one : 1
? Number two : 2
The sum is 3
~ rit math sum numbers --rit_number_one="1" --rit_number_two="2"
The sum is 3
If you want to test your formula more, see some suggestions below:
👉 If you’ve completed this first tutorial, let’s go to the second one How to use GitHub crendentials.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.