[英]Convert Python Script to Google Sheets Script
The following code block is a python script with added Google Sheets script method title and arguments. 以下代码块是python脚本,其中添加了Google Sheets脚本方法的标题和参数。 I would like to use this code in a Google Sheets custom script.
我想在Google表格自定义脚本中使用此代码。
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++) {}
for i in range(1,21):
可以转换为for (var i=1; i<21; i++) {}
f i+INPUT1 > j+INPUT2:
can be converted to if (i+INPUT1 > j+INPUT2) {}
f i+INPUT1 > j+INPUT2:
可以转换为if (i+INPUT1 > j+INPUT2) {}
print(count)
was converted to return count
for importing the result to the cell. print(count)
转换为用于将结果导入到单元格的return count
。 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. =D20PROBS(number, number)
放入单元格中。 INPUT1
and INPUT2
are necessary to be numbers. INPUT1
和INPUT2
必须是数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.