Reputation: 340
The following code block is a python script with added Google Sheets script method title and arguments. I would like to use this code in a Google Sheets custom script.
function D20PROBS(INPUT1, INPUT2) {
count=0
for i in range(1,21):
for j in range(1,21):
if i+INPUT1 > j+INPUT2:
count+=1
print(count)
}
Upvotes: 0
Views: 2171
Reputation: 201418
How about the following modifications?
for i in range(1,21):
can be converted to for (var i=1; i<21; i++) {}
f i+INPUT1 > j+INPUT2:
can be converted to if (i+INPUT1 > j+INPUT2) {}
print(count)
was converted to return count
for importing the result to the cell.function D20PROBS(INPUT1, INPUT2) {
var count = 0;
for (var i=1; i<21; i++) {
for (var j=1; j<21; j++) {
if (i+INPUT1 > j+INPUT2) {
count+=1;
}
}
}
return count;
}
=D20PROBS(number, number)
to a cell.INPUT1
and INPUT2
are necessary to be numbers.Upvotes: 1