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)
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.