Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. 知识库
  3. 二维积木
  4. 比较大小运算

比较大小运算

Scheduled Pinned Locked Moved 二维积木
1 Posts 1 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    creaticodeteacher2-mail
    wrote on last edited by admin
    #1

     

    先修科目

    • 组装积木

     

    介绍

    在“运算”这一组,有6个布尔型积木(>、<、≠、=、>=、<=)用于比较数字或文本。例如,你可以比较3和5哪个大,也可以比较“苹果”和“橘子”。比较结果为“true(真)”或“false(假)”。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/58377a6e-f0e2-488f-b181-9039bbf54269.png" width="600" style="">
     
     

    比较数字

    你可以用这6个积木来比较两个数,与数学中比较两数的方法相同。

    例如,当你运行积木“10>5”,返回值为“true(真)”。然而,如果你问“5>5”或者“5>10”,结果就为“false(假)”。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ac482d0c-7959-4f7b-a8c9-b8abfcabcfde.gif" width="500" style="">

    提醒一下,如果两数相等,积木≥和≤会返回“true(真)”。例如:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/601c7d09-c809-46ca-ab36-56af0b8466da.gif" width="500" style="">

     
     

    比较单个字母

    如果你比较单个字母,比如“a”和“b”,计算机将比较它们在字母表a-z中的位置。例如,“a”在字母表第1个,“b”在字母表第2个。由于1小于2,那么我们就说“a小于b”。显然,字母“z”大于其它所有字母。更多例子如下:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/23ca6825-a6d7-4605-b4d7-bb4146dbd0db.gif" width="500" style="">

     
    注意,在比较字母时不区分大小写。大写字母在比较之前先转化为小写字母。例如:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c8071e3d-1baa-4f82-8c77-198425b893e9.gif" width="500" style="">

     

    比较中文字符

    在比较2个汉字时,其实是比较2个汉字的Unicode编码,例如,“创”的Unicode码为21019,“益”的Unicode码为30410,所以“创”<“益”。大家可上网查询汉字的Unicode编码。

    注意,在Unicode编码中,汉字排在英文字母后面,所以任意一个汉字都大于任意一个英文字母。
    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c93a3f33-4fd9-4a05-95e7-d7cbfca94203.gif" width="600" style="">
     

    比较包含若干字符的文本

    当文本中包含多个字符,我们需要从左到右逐个比较字符。

    例如,比较“君子坦荡荡”与“君子和而不同”:

    • 位置1:都为“君”,打成平手,那么我们继续看位置2;
    • 位置2:都为“子”,仍然不分上下,那么我们继续看位置3;
    • 位置3:“坦”对比“和”。因为“坦”的Unicode编码为22374,“和”的Unicode编码为21644,可知“坦”大于“和”。因此,我们可以到此为止并宣布“君子坦荡荡”>“君子和而不同”。

    更多示例如下:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/9ac17e82-11c2-407c-acc4-6f15aed1f11a.gif" width="700" style="">

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode