小编Jea*_*bre的帖子

类型错误:“complex”和“int”实例之间不支持“<=”

我正在用 Python 编写一个程序,但无法克服这个异常

\n\n
from cmath import sqrt;\n\na = int(input("Podaj pierwsza liczbe: "));\nb = int(input("Podaj druga liczbe: "));\nc = int(input("Podaj trzecia liczbe: "));\n\nif a<=0:\n    print("Nie mo\xc5\xbcna policzyc delty");\nelse:\n        delta = sqrt(b*b-4*a*c);\n        print("delta wynosi:",delta);\n\nif (delta <= 0):\n    print("Nie obliczymy miejsca zerowe");\nelif (delta == 0):\n        x = -b/(2*a);\n        print("Miejsce zerowe wynosi:",x);\nelif (delta >= 0):\n        x1 = ((-b-delta)/(2*a));\n        x2 = ((-b+delta)/(2*a));\n        print("Pierwsze miejsce zerowe wynosi:",x1);\n        print("Drugie miejsce zerowe:",x2);\n\n\n\nTraceback (most recent call last):\n  File "C:/Users/Administrator/AppData/Local/Programs/Python/Python36-32/Rownanie kwadratowe.py", line 14, in <module>\n    if (delta <= 0):\nTypeError: …
Run Code Online (Sandbox Code Playgroud)

python

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

raise 和 except 和有什么不一样?

当我们必须处理异常时,引发异常有什么意义?是因为引发异常允许您创建自己定义的异常吗?

except:
  raise ZeroDivisionError
Run Code Online (Sandbox Code Playgroud)

对比

except ZeroDivisionError:
  #code
Run Code Online (Sandbox Code Playgroud)

python

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

通过值引用传递向量不会改变传递的原始向量?

我正在练习 C++ 中的函数指针。我编写了以下代码。我已经声明了一个整数向量并向其添加了值。之后,我通过引用将向量的值传递给函数。我将值添加到向量的每个值中。之后,当我显示原始向量的内容时,这些值不会改变。以下是代码。

void printValues (int val) {

    cout << val << " ";

}

void ForEach (vector<int> values, void (* func )(int), int inc) {

    for (int value : values) {
        value = value + inc;
        func (value);
    }
}

int main() 
{   
    vector<int> v1;
    cout << "Please enter the values in vector";
    for (int i = 0; i < 5; i++) {
        int val = 0;
        cin >> val;
        v1.push_back(val);
    }



    cout << "value stored in vector :" …
Run Code Online (Sandbox Code Playgroud)

c++ stl function-pointers pass-by-reference

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

如何将字典值转换为字符串

如何将此字典的值转换为字符串

d = {(0, 0): 'S', (1, 1): 'T', (2, 2): 'A', (3, 3): 'C', 
      (4, 4): 'K', (5, 5): 'O', (6, 6): 'V', (5, 7): 'E',
      (4, 8): 'R', (3, 9): 'F', (2, 10): 'L', (1, 11): 'O',
      (0, 12): 'W', (1, 13): 'T', (2, 14): 'E', (3, 15): 'S',
      (4, 16): 'T'}
Run Code Online (Sandbox Code Playgroud)

我如何对输出进行排序?

(0, 0), (0, 12),(1, 1),(1, 11) ....
Run Code Online (Sandbox Code Playgroud)

我想获取 str 方法给我的一个字符串中的所有值

dict_values(['S', 'T', 'A', 'C', 'K', 'O', 'V', 'E', 'R', 'F', 'L', 'O', 'W', 'T', 'E', …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

(Python) 如何检查 http 响应状态

有人可以告诉我如何使用 http.client 检查 HTTP 响应的状态码吗?我在 http.client 的纪录片中没有找到任何具体内容。代码如下所示:

  if conn.getresponse():
    return True #Statuscode = 200
  else:
    return False #Statuscode != 200
Run Code Online (Sandbox Code Playgroud)

我的代码看起来像这样:

from urllib.parse import urlparse
import http.client, sys

def check_url(url):
  url = urlparse(url)
  conn = http.client.HTTPConnection(url.netloc)
  conn.request("HEAD", url.path)
  r = conn.getresponse()
  if r.status == 200:
    return True
  else:
    return False

if __name__ == "__main__":
  input_url=input("Enter the website to be checked (beginning with www):")
  url = "http://"+input_url
  url_https = "https://"+input_url
  if check_url(url_https):
    print("The entered Website supports HTTPS.")
  else:
    if check_url(url):
      print("The …
Run Code Online (Sandbox Code Playgroud)

python http response status

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

在printf中输出变量地址

如果我在Visual C++ 2017中构建并运行以下程序:

#include <stdio.h>

int main()
{
    int a[3] = { 0 };

    for (int i = 0; i < 3; i++)
    {
        printf("%llu %u %p\n", a + i, a + i, a + i);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我看到输出如下:

31519768560270096 7338768 000F1055
31519785740139284 7338772 000F1055
31519802920008472 7338776 000F1055
Run Code Online (Sandbox Code Playgroud)

我无法联想到.

为什么输出%llu如此不同?sizeof(int)在我的平台上是4.

为什么输出%p都相同?它们是不同变量的地址.

只有输出%u似乎是一致的 - 3个数组元素的连续内存位置,每个数组元素有4个字节.但这些输出既不匹配%llu也不匹配%p.

c pointers

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

汇编代码 fsqrt 和 fmul 指令

我正在尝试1.34 *sqrt(lght)使用内联汇编在此函数中进行计算,但出现以下错误:

'_asm' 未声明(首次在此函数中使用)每个未声明的标识符仅针对它出现在预期中的每个函数报告一次 ';' 在“{”标记之前


我一直在研究如何解决这个问题,但找不到太多信息。有人可以建议一种方法来让它发挥作用吗?

我的代码是:

   double hullSpeed(double lgth) {
       _asm {
           global _start
           fld lght; //load lght
           fld st(0); //duplicate lght on Top of stack
           fsqrt;
           square root of lght
           fld st(0); //load square result on top of stack
           fld 1.34; //load 1.34 on top of stack
           fld st(i);
           duplicate 1.34 on TOS
           fmulp st(0), st(i); //multiply them 
           fst z;
           save result in z
       }
       return z; // return result of [ 1.34 *sqrt(lght) ] …
Run Code Online (Sandbox Code Playgroud)

c x86 assembly gcc inline-assembly

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