运算符#

介绍#

VEXcode GO 中的运算符模块用于处理数学计算和字符串操作。这些模块允许执行算术运算、评估条件和处理文本。

Below is a list of all blocks:

  • math operator — Performs addition, subtraction, multiplication, or division.

  • comparison operator — Compares two values using greater than, less than, or equal operators.

  • logical operator — Evaluates multiple conditions using and or or.

  • not operator — Inverts a Boolean value.

  • range operator — Checks if a number falls within a range.

  • pick random — Generates a random number within a specified range.

  • round number — Rounds a number to the nearest whole number.

  • math functions — Applies operations such as square root, trigonometry, logarithms, and exponentiation.

  • remainder — Returns the remainder of a division operation.

  • join — Combines two strings into one.

  • letter — Extracts a character from a string by position.

  • length — Returns the number of characters in a string.

  • contains — Checks if a string includes a specific word or character.

  • convert — Converts a number into text, a whole number, or a decimal.

数学运算符#

The math operator block performs basic arithmetic on the values placed on either side. It returns a result based on the project’s print precision, which defaults to 0 decimal places but can be adjusted using the set print precision block.

数学运算符报告器块。#
([0] [math_plus v] [0])

参数

描述

值 1

运算中使用的第一个数字。

操作员

The mathematical operator to use:

  • + — Addition
  • - — Subtraction
  • * — Multiplication
  • / — Division

值 2

运算中使用的第二个数字。

例子

当开始 :: hat events
[Perform basic addition and show two decimal places.]
设定打印精度为 [0.01 v]
打印 ([10] [math_plus v] [10.5]) ▶

比较运算符#

比较运算符块返回一个布尔值,指示两个值之间的比较是真还是假。

  • True — The comparison is correct (e.g., 5 > 3 returns True).

  • False — The comparison is incorrect (e.g., 2 ≥ 5 returns False).

比较运算符布尔块。#
<[0] [math_equal v] [0]>

范围

描述

值 1

要比较的第一个值。

操作员

The comparison to use:

  • = — Equal to
  • < — Less than
  • — Less than or equal to
  • > — Greater than
  • — Greater than or equal to

值 2

要比较的第二个值。

例子

当开始 :: hat events
[Build Used: Code Base 2.0]
[Turn right until the heading reaches 90 degrees.]
[右 v] 转
等待 [0.5] 秒
等到 <(底盘归位角度值) [math_greater_than v] [90]>
驱动停止

逻辑运算符#

逻辑运算符块返回一个布尔值,指示多个值之间的逻辑条件是真还是假。

  • True — The logic condition is met.

  • False — The logic condition is not met.

逻辑运算符布尔块。#
<<> [and v] <>>

范围

描述

条件 1

要评估的第一个布尔条件。

操作员

The logical operator to use:

  • and — Returns True if both conditions are True.
  • or — Returns True if at least one condition is True.

条件 2

要评估的第二个布尔条件。

例子

当开始 :: hat events
[Build Used: Super Code Base 2.0]
[Drive forward and pick up a red or green Disk.]
驱动 [向前 v]
等到 <<辨色仪测得 [红色 v]?> [or v] <辨色仪测得 [绿色 v]?>>
驱动停止
使 [magnet v] 加磁 [boost v]

非运算符#

非运算符 块用于对布尔块的结果进行取反。如果输入为 True,则返回 False;如果输入为 False,则返回 True。

  • True — The input condition would normally return False.

  • False — The input condition would normally return True.

非运算符布尔块。#
<非 <>>

范围

描述

状况

要反转的布尔条件。

例子

当开始 :: hat events
[Build Used: Code Base 2.0]
[Turn until the robot is facing left. ]
永久循环
如果 <非 <(底盘归位角度值) [math_greater_than v] [270]>> 那么
[右 v] 转
否则
驱动停止

范围运算符#

范围运算符块返回一个布尔值,指示某个值是否在指定范围内。

  • True — If the value is within the range.

  • False — If the value is outside the range.

范围运算符布尔块。#
<[0] [math_less_than v] [0] [math_less_than v] [0]>

范围

描述

第一操作员

The comparison operator to use:

  • < - Less than
  • ≤ - Less than or equal to
  • > — Greater than
  • ≥ — Greater than or equal to

价值

要检查的值。

第二操作员

The comparison operator to use:

  • < — Less than
  • ≤ — Less than or equal to
  • > — Greater than
  • ≥ — Greater than or equal to

例子

当开始 :: hat events
[Build Used: Code Base 2.0]
[Turn and display when facing forward or back. ]
[右 v] 转 [360] 度 ◀ 并且不等待
永久循环
清除所有行
如果 <[270] [math_greater_than v] (底盘归位角度值) [math_greater_than v] [90]> 那么
打印 [Facing backward!] ▶
否则
打印 [Facing forward!] ▶
结束
等待 [1] 秒

随机选择#

选择随机块返回指定范围内的随机整数。

随机挑选记者区块。#
在 [1] 到 [10] 之间选随机数

参数

描述

分钟

可以选择的最低可能数字。

最大限度

可以选取的最大数字。

示例

当开始 :: hat events
[Display a number between 1 and 10.]
打印 (在 [1] 到 [10] 之间选随机数) ▶

整数#

round number 块按照标准舍入规则返回四舍五入到最接近的整数的给定数字:

  • 如果小数为 0.5 或更大,则数字向上舍入。

  • 如果小数小于 0.5,则数字向下舍入。

整数报告器区块。#
([0] 四舍五入到 [0] 位小数)

范围

描述

数字

要舍入的数字。

小数位

要四舍五入的小数位数。

例子

当开始 :: hat events
[Display the rounded result of 10 / 3.]
设定打印精度为 [0.01 v]
打印 (([10] [math_division v] [3]) 四舍五入到 [1] 位小数) ▶

数学函数#

数学函数 模块将选定的数学函数应用于给定数字并返回结果。它支持绝对值、舍入、平方根、三角函数、对数和指数等运算。

数学函数报告块。#
[abs v] 的 [0]

范围

描述

功能

对输入值应用的数学运算:

  • abs - 绝对值
  • floor - 向下舍入
  • ceiling - 向上舍入
  • sqrt - 平方根
  • sin - 正弦
  • cos - 余弦
  • tan - 正切
  • asin - 反正弦
  • acos - 反余弦
  • atan - 反正切
  • ln - 自然对数
  • log - 以 10 为底的对数
  • e^ - 欧拉数的幂
  • 10^ - 10 的幂
  • negative - 返回数字的负数

数字

应用该函数的数字。

例子

当开始 :: hat events
[Display the square root of 16.]
打印 ([sqrt v] 的 [16]) ▶

#

remainder 块返回两个值之间除法运算的余数。

剩余部分报告器块。#
([0] / [0] 取余)

范围

描述

股利

待除数。

除数

要除以的数字。

例子

当开始 :: hat events
[Display the remainder of 10 / 3.]
打印 ([10] / [3] 取余) ▶

加入#

join 块返回一个由两个或多个输入字符串组合而成的字符串。

加入记者区块。#
(连接 [apple] [banana])

范围

描述

字符串 1

第一个要合并的字符串。

字符串 2

要合并的第二个字符串。

当开始 :: hat events
[Display "VEXcode" on the Console.]
打印 (连接 [VEX] [code]) ▶

#

字母 从给定字符串中的指定位置返回单字符的字符串。

快报记者阻拦。#
([apple] 的第 [1] 个字符)

范围

描述

位置

字符串中字符的位置(从 1 开始)。

细绳

要从中提取字母的字符串。

当开始 :: hat events
[Display the first letter of "Robot".]
打印 ([Robot] 的第 (1) 个字符) ▶

长度#

length 块返回指定字符串中的字符数,包括空格。

长度报告块。#
([apple] 长度 :: operators)

范围

描述

细绳

要测量长度的字符串。

例子

当开始 :: hat events
[Count the number of characters in "VEX Robotics".]
打印 ([VEX Robotics] 长度 :: operators) ▶

包含#

contains 块返回一个布尔值,指示指定的字符串是否包含给定的单词或字符。

  • True — The string includes that specific word or character.

  • False — The string does not include that specific word or character.

包含布尔块。#
<[apple] 包含 [a]?>

范围

描述

细绳

要搜索的主字符串。

搜索词

要在字符串中检查的单词或字符。

例子

当开始 :: hat events
[Check if "robotics" contains "bot".]
如果 <[robotics] 包含 [bot]?> 那么
打印 [The word contains "bot".] ▶
否则
打印 [Not found.] ▶
结束

转变#

convert 块返回转换为指定类型的数字值,可以是文本或数字。

  • text — Converts the number to a string. Numbers must be in string format to be combined with text.

  • number — Converts the number to a decimal (floating-point) value.

转换报告器块。#
(转换 [0] 为 [文本 v])

范围

描述

价值

要转换的数字。

类型

将数字转换为的类型:

  • 文本
  • 数字

例子

当开始 :: hat events
[Build Used: Code Base 2.0]
[Display the robot's heading as it turns.]
[右 v] 转
永久循环
清除所有行
打印 (连接 [Currently facing: ] (转换 (底盘归位角度值) 为 [文本 v])) ▶
等待 [0.5] 秒