RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
alexWithoutBeard
Asked: 2024-08-21 16:00:14 +0000 UTC

给出了一个链接、一个段落和一个按钮。单击按钮时,将链接的 href 写入段落文本中

  • 5

单击按钮时,所有链接都必须添加到段落中,而不仅仅是一个链接,就像现在一样

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Test</title>
  </head>
  <body>
    <a  id="am" href="url1.html">url1</a><br />
    <a id="am2" href="url2.html">url2</a><br />
    <p id="test_p"></p>
    <button id="button">Вычислить</button>
    <script>
      document
        .getElementById("button")
        .addEventListener("click", function () {
          href = document.getElementById("am").getAttribute("href");
          p = document.getElementById("test_p");
          p.innerHTML = href;
        });
    </script>
  </body>
</html>

我尝试了 forof 和 for 的选项,但没有任何效果对我来说(

javascript
  • 1 个回答
  • 24 Views
Martin Hope
kulpinss
Asked: 2024-08-21 12:13:46 +0000 UTC

我需要帮助解决 Python 中的问题

  • 5

该数据库存储您服务的真实用户列表,包括几个测试用户。程序在第一行获取所有用户的完整列表,在第二行获取列表中测试用户的索引。使用 for 循环,仅在一行上打印真实的用户名。

输入示例 1:

Alice, Bob, Charlie, Dave, Eve  
1, 3  

示例输出 1:

Alice Charlie Eve  

输入示例 2:

Alice, Bob, Charlie  
0, 2  

示例输出 2:

Bob  

我决定这样

full_list=input().split(", ") # full_list=['Alice', 'Bob', 'Charlie', 'Dave', 'Eve']
indexes=list(map(int, input().split(", "))) # indexes=[1, 3]
real_list=[]
for i, text in enumerate(full_list):
    if indexes[0]==i:
        continue
    if indexes[1]==i:
        continue
    real_list.append(text)    
print(*real_list)

在沙箱中一切都很好,答案是正确的,但在教育课程中该解决方案不起作用。问题

Failed test #3 of 3. Runtime error
Error:
Traceback (most recent call last):
  File "jailed_code", line 8, in <module>
    if indexes[1]==i:
IndexError: list index out of range

我尝试使用 while

full_list=input().split(", ")
a,b=list(map(int, input().split(", ")))
i=0
names_of_real_users=[]
while len(full_list)>i:
    names_of_real_users=full_list[i]
    i=i+1
    if names_of_real_users==full_list[a]:
        continue
    if names_of_real_users==full_list[b]:
        continue
    print(names_of_real_users, end=" ")

这次的错误是:

Failed test #3 of 3. Runtime error
Error:
Traceback (most recent call last):
  File "jailed_code", line 3, in <module>
    a,b=list(map(int, input().split(", ")))
ValueError: not enough values to unpack (expected 2, got 1)
python
  • 2 个回答
  • 59 Views
Martin Hope
rost
Asked: 2024-08-21 10:36:48 +0000 UTC

如何将控制台的全部内容复制到字符串中? | C++

  • 5

如何将终端的全部内容复制到一行中,以便我可以对此内容执行某些操作并将更改的内容粘贴到终端中?如果问题不完全清楚,那么代码可能如下所示:

#include <iostream>
#include <string>
#include <stdlib.h>

int main() {
    std::string consoleInsd = get_console(); // тут нужно получить содержимое консоли
    int lenght = consoleInsd.length();
    consoleInsd = consoleInsd.substr(0, length - 10); // для примера хочу убрать последние 10 символов
    system("clear");
    std::cout << consoleInsd;

    return 0;
}
c++
  • 2 个回答
  • 37 Views
Martin Hope
Федор Яроцкий.
Asked: 2024-08-21 04:16:03 +0000 UTC

通过 C++ 中的 COM 端口使用 Arduino

  • 5

我需要将数据从计算机传输到Arduino Uno,然后从Arduino接收其他数据到计算机。我在 Arduino 和使用 C++ 的计算机上编写了实现此逻辑的代码。不幸的是,代码只有在刷新 Arduino Uno 固件后才能立即正常工作。但是,如果您断开Arduino与COM端口的连接,然后再次连接,计算机将无法将数据传输到开发板。可能是什么原因?计算机代码

#include <windows.h>
#include <iostream>
using namespace std;

HANDLE serial;
char outData[] = "s";
DWORD outDataSize = sizeof(outData);
DWORD outBytesWritten;

void SerialRead() {
    DWORD inputDataSize;
    char receivedChar;
    while (true) {
        ReadFile(serial, &receivedChar, 1, &inputDataSize, 0); 
        if (inputDataSize > 0) cout << receivedChar;
    }
}

int main(){
    cout << ">> begin\n";
    LPCTSTR name = L"COM4";
    DCB sParams;

    serial = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    if (serial == INVALID_HANDLE_VALUE){
        if (GetLastError() == ERROR_FILE_NOT_FOUND){
            cout << ">> serial port does not exist\n";
            CloseHandle(serial);
            return 0;
        }
        cout << ">> some other error occurred\n";
        CloseHandle(serial);
        return 0;
    }

    if (!GetCommState(serial, &sParams)) {
        cout << ">> getting state error\n";
        CloseHandle(serial);
        return 0;
    }
    sParams.BaudRate = CBR_9600;
    sParams.ByteSize = 8;
    sParams.StopBits = ONESTOPBIT;
    sParams.Parity = NOPARITY;
    if (!SetCommState(serial, &sParams)) {
        cout << ">> error setting serial port state\n";
        CloseHandle(serial);
        return 0;
    }

    BOOL write = WriteFile(serial, outData, outDataSize, &outBytesWritten, NULL);
    cout << write;

    cout << ">> reading\n";
    while (true) SerialRead();

    return 0;
}

Arduino Uno 代码

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.read() == 's') Serial.print('e');
}
c++
  • 1 个回答
  • 31 Views
Martin Hope
Фангенто
Asked: 2024-08-21 01:22:24 +0000 UTC

C#。是否可以重载静态类?

  • 5

我知道对于普通类来说,重载是不可能的,因为不清楚该对象属于哪个类。那么静态的呢?他们不能有物体。我只想向 File 类添加尽可能多的方法(这些方法当前位于具有不同名称的类中)。

c#
  • 1 个回答
  • 73 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5