小编Joa*_*uer的帖子

我可以从列表中随机选择...但是如何将其用作不同命令的变量?蟒蛇

可以说我有以下内容:

foo = ('animal', 'vegetable', 'mineral')
Run Code Online (Sandbox Code Playgroud)

我希望能够从列表中随机选择THEN,具体取决于选择哪一个,具有一组要遵循的命令.

例如,如果随机选择"动物",我想要打印消息('rawr I \'ma tiger'),或者如果它是'蔬菜'打印('Woof,我是胡萝卜')或其他东西.

我知道随机选择它是:

from random import choice
print choice(foo)
Run Code Online (Sandbox Code Playgroud)

但我不希望打印的选择,我希望它是秘密的.请帮忙.

python printing random list choice

0
推荐指数
1
解决办法
350
查看次数

for loop(记得最后看的地方)&Character.isDigit()

我必须做一个关于元素周期表的项目.我的困境如下.用户会向您发送分子方程式.它可以是任何长度.在这个数组中有大写字母,小写字母和数字.

我也有一个对象数组.每个对象代表元素周期表上的元素.现在我需要打破这个字符串,用户将我发送给更小的片段 - 由对象数组识别的片段.我还必须将答案乘以元素的最后一个字母旁边的数字或数字.

我已经尝试了以下内容.使字符串成为char数组.从后面运行数组 - 测试number(Character.isDigit(a[i]);),测试大写和小写......我总是遇到同样的问题.我不知道字符串会有多长.让我们说我找到一个数字.然后,如果前一个字符是小写字母,我需要另外检查大写字母.然后让我说我有分子方程式和我需要乘以的数量 - 如何让计算机知道从最后一个大写字母开始查看.

我希望有人理解这一点!

真的需要一些帮助.

另一个问题:为什么来这个代码不起作用:

String moleq = "HeKiLH2B6";

char[] a = moleq.toCharArray();
int g = moleq.length()-1;
int x = 1; //if not more than one of element - multiply getWeight by 1

int[][] indexofdigit = new int[moleq.length()][2];
int[] indexoflower = new int[moleq.length()];

for (int i = g; i <= 0; i--){

    if (Character.isDigit(a[i])) {
    String z = Character.toString(a[i]);
    x = Integer.parseInt(z);
    System.out.println("YES");

    }
}
Run Code Online (Sandbox Code Playgroud)

这段代码永远不会打印出来是的?

java for-loop char

0
推荐指数
1
解决办法
770
查看次数

Shell脚本中的Nested-If语句

这是我的脚本:

echo "Name"

read name

if [ "$name" == "abcd" ]; then

 echo "Password"

 read password

 if [ "$password == "pwd" ]; then

  echo "Hello"

 else

  echo "Wrong password"

 fi

else

 echo "wrong username"

fi
Run Code Online (Sandbox Code Playgroud)

这是我运行时得到的输出:

sh hello.sh

Name

abcd

hello.sh: line 14: unexpected EOF while looking for matching `"'

hello.sh: line 16: syntax error: unexpected end of file

这里有什么想法吗?这可能是一个非常愚蠢的,但我浪费了将近一个小时.

unix shell nested-if

0
推荐指数
1
解决办法
7万
查看次数

如何访问系统公共目录

我需要帮助找到操作系统的公共目录,我可以在其中保存带有信息的.txt文件.

我解释得更好:我必须保存一个txt文件,我已经保存了一些重要的信息,但我必须将我的程序提供给来自世界各地的不同的人,我不能使用名为"Users"的目录因为它将以操作系统的语言翻译.

所以我正在寻找一个在所有语言中具有相同名称的目录,或者更好的是一个对象的方法,它可以让我访问无法重命名的操作系统的公共目录,并且可以在所有操作系统中找到.

谁能帮我?

java directory

0
推荐指数
1
解决办法
154
查看次数

无法打开文件

我正在创建一个程序来读取FASTA文件并拆分某些特定字符,例如' >'等等.但是我遇到了问题.

计划部分是:

>>> def read_FASTA_strings(seq_fasta):
...     with open(seq_fasta.txt) as file: 
...             return file.read().split('>') 
Run Code Online (Sandbox Code Playgroud)

错误---

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'seq_fasta' is not defined
Run Code Online (Sandbox Code Playgroud)

如何摆脱这个问题?

python file-io

0
推荐指数
1
解决办法
633
查看次数

Joda DateTime没有给出预期的结果

鉴于DateTime2011年3月31日的对象和此代码:

DateTime temp1 = new DateTime(2011, 3, 31, 12, 0, 0, 0);
DateTime temp2 = temp1.plusMonths(1);
DateTime temp3 = temp2.plusMonths(1);
Run Code Online (Sandbox Code Playgroud)

执行后

temp1 = 2011-03-31T12:00:00.000+02:00
temp2 = 2011-04-30T12:00:00.000+02:00
temp3 = 2011-05-30T12:00:00.000+02:00
Run Code Online (Sandbox Code Playgroud)

temp3在这里错了.

这是正确的吗?我做错了吗?

java jodatime

0
推荐指数
1
解决办法
131
查看次数

我不知道符号是什么,"#"在nutch的HttpBase.java的下面的src中是什么意思

当我来到nutch的下面的src时HttpBase.java,我不知道符号是什么,"#"在作者的描述中是什么意思:

// get # of threads already accessing this addr
Integer counter = (Integer)THREADS_PER_HOST_COUNT.get(host);
Run Code Online (Sandbox Code Playgroud)

java hadoop nutch

0
推荐指数
1
解决办法
107
查看次数

我们可以在HashMap <K,V>中为K分配哪些类型?

我们可以指定什么类型KHashMap<K,V>?它只是数字类型(int,float)还是我们可以分配用户定义的对象?

java hashmap

0
推荐指数
2
解决办法
462
查看次数

如何在C++中开发自己的GUI而不是Win32 API?

我想用C++开发自己的GUI.我的意思是从头开始.我对使用Win32 API,MFC,.NET或类似的东西不感兴趣.我想从头开始创建和开发所有东西.我想自己做一切.我只想要一些链接,参考或书籍.任何给我这方面指导的东西.

有人可以帮忙吗?

c++ windows

0
推荐指数
1
解决办法
1854
查看次数

声纳违规:"方法可能无法关闭异常"

我有这个方法:

 private void unZipElementsTo(String inputZipFileName, String destPath) throws FileNotFoundException, IOException {

        OutputStream out = null;
        InputStream in = null;
        ZipFile zf = null;

        try {
            zf = new ZipFile(inputZipFileName);

            for (Enumeration<? extends ZipEntry> em = zf.entries(); em.hasMoreElements();) {
                ZipEntry entry = em.nextElement();
                String targetFile = destPath + FILE_SEPARATOR + entry.toString().replace("/", FILE_SEPARATOR);
                File temp = new File(targetFile);

                if (!temp.getParentFile().exists()) {
                    temp.getParentFile().mkdirs();
                }

                in = zf.getInputStream(entry);

                out = new FileOutputStream(targetFile);
                byte[] buf = new byte[4096];
                int len;
                while ((len = in.read(buf)) > …
Run Code Online (Sandbox Code Playgroud)

java exception inputstream sonarqube

0
推荐指数
1
解决办法
8061
查看次数