如何让计算机选择随机变量并显示它? [英] How do I get the computer to choose a random variable and display it?

查看:67
本文介绍了如何让计算机选择随机变量并显示它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppLab中编码,这是Code.Org中使用的编码语言。



我正试图让计算机显示在一个文本框中,四个文本变量之一,标题为正手,反手,切片或粉碎。我遇到的问题是,唯一可用的Randomizer功能是RandomNumber(#,#)的功能,你可以猜测,它只接受数字。因此,我尝试为每个文本变量分配一个数字,并让计算机随机选择1-4之间的数字,其中每个数字都分配了一个文本变量,如正手,反手等。



我不知道怎么做。有什么帮助吗?



我尝试了什么:



我试图为每个文本变量分配一个数字,并让计算机随机选择1-4之间的数字,其中每个数字都分配一个文本变量,如正手,反手等。

解决方案

你有你的兰特[1,2,3,4]

你有阵列[word,word,word,word]



triforce你有你的解决方案



array [rand] =word



在AppLab中也是如此,因为它有多种语言版本。 triforce我的猜测是执行不是你的问题,而是理解。



这是我的参考: App Lab Docs | Code.org [ ^ ]

学习谷歌,然后学习提问,并且总是学习^ _ ^



问候

Andy ^ _ ^

I'm coding in AppLab, the coding language used in Code.Org.

I'm trying to get the computer to display, in a text box, one of four text variables, titled "Forehand, Backhand, Slice, or Smash." The problem I'm having is that the only Randomizer function available is that of the RandomNumber(#,#), which as you can probably guess, only accepts numbers. Therefore, I attempted to assign each text variable with a number, and to have the computer randomly select a number between 1-4, where each number is assigned a text variable like Forehand, Backhand, etc.

I've no idea how to do it though. Any help?

What I have tried:

I attempted to assign each text variable with a number, and to have the computer randomly select a number between 1-4, where each number is assigned a text variable like Forehand, Backhand, etc.

解决方案

You have your rand [1,2,3,4]
you have your array ["word","word","word","word"]

"triforce" you have your solution

array[rand] = "word"

That is true in AppLab as it is in many languages. "triforce" my guess is that the execution is not your issue, but understanding.

Here is my reference:App Lab Docs | Code.org[^]
Learn to google, then learn to question, and always learn ^_^

Regards
Andy ^_^


这篇关于如何让计算机选择随机变量并显示它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆