小编mat*_*ttm的帖子

类实例不可迭代

在我的功能中,我有:

        """
        Iterates 300 times as attempts, each having an inner-loop
        to calculate the z of a neighboring point and returns the optimal                 
        """

        pointList = []
        max_p = None

        for attempts in range(300):

            neighborList = ( (x - d, y), (x + d, y), (x, y - d), (x, y + d) )

            for neighbor in neighborList:
                z = evaluate( neighbor[0], neighbor[1] )
                point = None
                point = Point3D( neighbor[0], neighbor[1], z)
                pointList += point
            max_p = maxPoint( pointList …
Run Code Online (Sandbox Code Playgroud)

python iterable class hill-climbing

2
推荐指数
1
解决办法
4806
查看次数

在main中使用函数的局部变量

我试着寻找芒果,但所有的线程都是不同的.

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

void calcDistance (int x1, int y1, int x2, int y2);

int main()
{
    int x1, y1, x2, y2;
    cout << "Enter the points in coordinate pair form, ommiting parantheses" << endl;
    cin >> x1 >> y1 >> x2 >> y2;

    calcDistance (x1,  y1,  x2,  y2);

    system("pause");
    // how do I cout the dist in main-- says dist isn't declared

}


void calcDistance (int x1, int y1, int x2, int y2) …
Run Code Online (Sandbox Code Playgroud)

c++ function

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

在c ++中使用双精度时模数不起作用

我不被允许使用mod.我认为这不起作用,因为我正在使用双打; 有没有解决的办法?---评论区域工作

void displayResults(double num1, char oper, double num2)
{
     switch(oper)
     {
     case '+' :
     cout << num1 << "+" << num2 << "=" << (num1+num2) << endl;
     break;

     case '-' :
     cout << num1 << "-" << num2 << "=" << (num1-num2) << endl;
     break;

     case '*' :
     cout << num1 << "*" << num2 << "=" << (num1*num2) << endl;
     break; 

     case '/' :
          if ( num1==0 || num2==0)
          cout <<"A number divided by 0 or divided into …
Run Code Online (Sandbox Code Playgroud)

c++

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

Python 3给了我无法解决的错误

下面是代码:

import turtle
import math

def drawTree(segments,size):
    """
    :param segments: refers to number of extensions from the previous
    :param size: refers to the length of the initial extension
    """
    if (segments < 0.0 | size < 0.0):
        print("Invalid Input")
    elif (segments == 0 | size == 0):
        pass
    elif segments > 0:
        i = 1
        for i in range(6):
            turtle.down()
            turtle.forward(size)
            turtle.back(size)
            turtle.right(60)
            i -= 1
            if segments != 0:
                size *= (1/3)
                turtle.forward(size)
                turtle.back(size)
                segments -= 1
                drawTree(segments, size) …
Run Code Online (Sandbox Code Playgroud)

python conditional

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

标签 统计

c++ ×2

python ×2

class ×1

conditional ×1

function ×1

hill-climbing ×1

iterable ×1