标签: for-loop

在python中产生以下输出(for和while循环)?

我有关于for和while循环的任务,我只是对某些东西感到困惑.如果你们能帮助我,我们将不胜感激.

问题是在python中使用for和while循环产生以下内容:

1
FredFredFredFred
2
FredFredFred
3
FredFred
4
Fred
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止的"for循环"

for i in range(1,5):
    print(i)
    print('Fred'*i)
Run Code Online (Sandbox Code Playgroud)

但我不能让'Fred'像他们要求的那样.

python loops for-loop while-loop python-3.x

-5
推荐指数
1
解决办法
466
查看次数

Python循环语法错误?

为什么这不会编译......我很难过......

for files in glob.glob("*.txt"):
    f=open(files)
    for lines in f:
        print lines
Run Code Online (Sandbox Code Playgroud)

我明白了:

File "teleparse.py", line 21
for lines in f:
^
IndentationError: unexpected indent
Run Code Online (Sandbox Code Playgroud)

python syntax loops for-loop

-6
推荐指数
1
解决办法
1389
查看次数

什么是C#方式相当于这个for循环?

我是C#的新手,日复一日地学习它的元素,来自C也让我感到困惑,因为像这样的简单for循环会起作用,所以为什么它不能在C#中工作,如果你能详细解释的话(如果可能的话)我会非常感激.

for (int i = 1; i <= 10; i++){

    public void question()
    {
        if (questionNr == 1)
        {
            questionLabel.Text = "What is Chuck's full name?";
            ans1.Text = "Charles Irving Bartowski";
            ans2.Text = "Charles Richard Bartowski";
            ans3.Text = "Charles Luke Bartowski";
            ans4.Text = "Zachary Strahovski";
        }
        else if (questionNr == 2)
        {
            questionLabel.Text = "Who/what is Orion?";
            ans1.Text = "Original name of the Intersect";
            ans2.Text = "Alias of a secret mission";
            ans3.Text = "Morgan's Xbox";
            ans4.Text = "Chuck's father";
        } …
Run Code Online (Sandbox Code Playgroud)

c# loops for-loop compiler-errors

-6
推荐指数
2
解决办法
250
查看次数

计算按钮点击之间的平均时间

我在C#中使用此Windows窗体应用程序,因此当您多次单击此按钮时,它会计算您每秒的平均点击次数.

我昨天开始学习C#,唯一擅长的语言是Lua.在Lua中,这很简单,只需使用表格,因为它们非常动态和灵活.我不知道如何在C#中做到这一点,MSDN文章只是让我困惑.

如何在点击之间存储时间?阵列?我没有线索.这是我到目前为止的按钮点击功能

private void button1_Click(object sender, EventArgs e)
{

    //DO STUFF

}
Run Code Online (Sandbox Code Playgroud)

c# arrays for-loop winforms

-6
推荐指数
1
解决办法
281
查看次数

Go中的嵌套循环数组不像其他语言的数组那样

为什么这个函数打印出一个[83 83 83 83 83]而不是[98 93 77 82 83]

package main

import "fmt"

func main() {
    var x [5]float64
    scores := [5]float64{ 98, 93, 77, 82, 83, }

    for i, _ := range x {
        for j, _ := range scores {
            // fill up x array with elements of scores array
            x[i] = scores[j]
        }
    }
    fmt.Println(x)
}
Run Code Online (Sandbox Code Playgroud)

arrays for-loop go

-6
推荐指数
1
解决办法
75
查看次数

C中双精度数组的优化和

我有一个任务,我必须采取一个程序,并使其在时间上更有效.原始代码是:

#include <stdio.h>
#include <stdlib.h>

// You are only allowed to make changes to this code as specified by the comments in it.

// The code you submit must have these two values.
#define N_TIMES     600000
#define ARRAY_SIZE   10000

int main(void)
{
    double  *array = calloc(ARRAY_SIZE, sizeof(double));
    double  sum = 0;
    int     i;

    // You can add variables between this comment ...
    long int help;
    // ... and this one.

    // Please change 'your name' to your actual name.
    printf("CS201 …
Run Code Online (Sandbox Code Playgroud)

c optimization performance for-loop

-6
推荐指数
1
解决办法
4104
查看次数

c ++循环的增量

好吧,我从来没有尝试过for循环.我想将for循环增加8而不是一般的后增量.我正在尝试这样的事情.

for(U8 i=3;i<=31;i+8,j++){
    Array[j]=(Status>>i) ;

    if (j>3){
        j = 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

好吧它给了我警告,就像逗号表达式的左手操作数没有效果.这个警告是什么意思?我的逻辑会起作用吗?status包含我系统的32位信息,我需要特殊的位.

c++ for-loop

-6
推荐指数
1
解决办法
735
查看次数

哪个for循环在C++中更有效?

我和我的朋友正在讨论这三个for循环中的哪一个在C++中更有效(仅作为示例目的,它们将循环10次):

//A) 
for(int i = 0; i<10; i++)
{
    // Do stuff. 
}

//B) 
for(int i = 0; i< 10; ++i)
{
    // Do stuff.
}

//C) 
for(int i = 11; --i;)
{
    // Do stuff.
}

// D) 
// Anything you guys know that is better.
Run Code Online (Sandbox Code Playgroud)

哪一个最好,为什么?

c++ performance for-loop

-6
推荐指数
1
解决办法
286
查看次数

如何遍历锯齿状数组中的每个元素?

我有一个二维数组,所以是一个数组数组。数组的数组不具有相同的长度。这里有一个例子:

double[][] multi = new double[][] { 
  { 10, 20, 30, 40, 50 }, 
  { 1.1, 2.2, 3.3, 4.4 }, 
  { 1.2, 3.2 },
  { 1, 2, 3, 4, 5, 6, 7, 8, 9 } 
};
Run Code Online (Sandbox Code Playgroud)

如何遍历列?(我爱:10 1.1 1.2 1

java arrays for-loop

-6
推荐指数
1
解决办法
2613
查看次数

为什么这不会导致无限循环?

来自Eloquent JavaScript.由于"i"从-1开始并在每个循环中减1,因此永远不会达到结束条件"i> = 0".然而代码有效.

function arrayToList(array) {
  var list = null;
  for (var i = array.length - 1; i >= 0; i--)
    list = {value: array[i], rest: list};
  return list;
}

console.log(arrayToList([]));
//null
Run Code Online (Sandbox Code Playgroud)

javascript arrays for-loop infinite-loop

-6
推荐指数
1
解决办法
112
查看次数