我有问题,仍然无法处理。:(这是我的代码
declare -i disk_usage_rate=$(df -h /appdata/SCT_CDR | cut -d '%' -f 1 | awk 'NR==2{print $5}')
while ["$disk_usage_rate" -gt 80]
do
...
...
done
Run Code Online (Sandbox Code Playgroud)
我从 df -h 命令获得磁盘使用率。但是在 while 循环中,我收到了 followig 错误。顺便说一句,它是 bash 脚本。
bash: [84: 找不到命令
我尝试了很多东西,但我还没有解决。
因此,对于我的程序,我需要检查本地网络上的客户端,该客户端运行着 Flask 服务器。这个 Flask 服务器正在返回一个可以改变的数字。
现在为了检索该值,我使用了请求库和 BeautifulSoup。
我想在脚本的另一部分使用检索到的值(同时不断检查其他客户端)。为此,我想我可以使用线程模块。
然而,问题是线程只在循环完成后才返回它的值,但循环需要是无限的。
这是我到目前为止得到的:
import threading
import requests
from bs4 import BeautifulSoup
def checkClient():
while True:
page = requests.get('http://192.168.1.25/8080')
soup = BeautifulSoup(page.text, 'html.parser')
value = soup.find('div', class_='valueDecibel')
print(value)
t1 = threading.Thread(target=checkClient, name=checkClient)
t1.start()
Run Code Online (Sandbox Code Playgroud)
有谁知道如何将打印的值返回给另一个函数?当然,您可以用某种 API 替换 requests.get url,其中值变化很大。
python infinite-loop while-loop python-multithreading python-3.x
whileTrue在不需要返回的 GNU Smalltalk 循环中,有什么简单而简洁的方法可以中断?
这是我的代码。如果char_stack为空,我想在第 31 行结束时中断循环。
https://gist.github.com/SYZYGY-DEV333/ea3f5eeb3473927c8faa294bb72a8858
任何帮助将非常感激。
我想请用户输入性别。如果用户的答案不是男性或女性,我想一遍又一遍地循环问题,直到用户输入男性或女性
这是我写的:
while not (mf):
gender=input("Next, the gender of the character is (male/female):")
if gender == ("male") or ("female"):
mf=True
else:
print("Enter the correct gender type.")
Run Code Online (Sandbox Code Playgroud)
如果我在问性别时输入女性,它会被视为错误,但女性和男性都应该是正确的答案。
抱歉,这段代码看起来很傻,但我只是想了解一下逻辑。
当用户quit作为输入输入时,我试图结束程序。
我写name != "quit" && sname != "quit"为 while 条件,所以如果它们中的任何一个是quit,循环就会结束(对吗?)。
但是当我写quit为时name,它仍然等待sname输入,如果我也为sname输入写退出,那么它最终结束。但是,quit自从我用 编写条件以来,它不应该在第一次看到时结束&&吗?
此外,当我用||. 为什么会这样?
int main()
{
string name="",sname="";
cout << "enter your name and surname \n";
cout << ">>name=";
getline(cin,name);
cout << ">>surname=";
getline(cin,sname);
while (name != "quit" && sname != "quit")
{
cout << ">>name=";
getline(cin,name);
cout << ">>surname=";
getline(cin,sname);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
enter your …Run Code Online (Sandbox Code Playgroud) 我编写了一个程序,它应该计算大小写字母和其他符号,但是当我单击 Enter 然后单击 ^C (EOF) 时,它会计算任何内容。我不知道如何跳过它,希望有人能以某种方式帮助我 <3
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
int uppers = 0, lowers = 0, others = 0;
while((ch = getchar()) != EOF)
{
if(islower(ch))
lowers++;
else if(isupper(ch))
uppers++;
else
others++;
}
printf("\n\nUpper letters - %d Lower letters - %d Others- %d", uppers, lowers, others);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有 id 的列表(列表)。作为使用 wget 进行在线检查的结果,该列表的每个元素都返回字符串“true”或“false”。我想遍历该列表,只要有一个元素返回“false”值。基本上我想重复这一点:
for i in range(len(list)):
wget online check
if status == 'true':
write id to another list
elif status == 'false':
continue
time.sleep()
Run Code Online (Sandbox Code Playgroud)
一遍又一遍,直到一切都是真的。
我用嵌套的 while 循环尝试了它:
for j in range(len(list)):
while status_ == 'false':
wget online check
if status == 'true':
write id to another list
elif status == 'false':
continue
time.sleep()
Run Code Online (Sandbox Code Playgroud)
但这不起作用。有人可以帮忙吗?
干杯
#include <stdlib.h>
#include <stdio.h>
enum {false, true};
int main()
{
int i = 1;
do
{
printf("%d\n", i);
i++;
if (i < 15)
continue;
} while (false);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
continue在这段代码中执行语句后会发生什么?
控制去哪儿了?
我有一个 while 循环,它询问用户的查询并接受响应,可以是一个词,也可以是一个句子。输出让我难以置信。
std::string response;
while (response != "!quit")
{
cout << "Query? ";
cin >> response;
if (response == "!quit")
{
cout << "Thank you for using this program!";
exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
Query? how are you
Query? Query? Query? how are you today
Query? Query? Query? Query? hi
Query?
Run Code Online (Sandbox Code Playgroud)
为什么它打印出与响应相同数量的单词的“查询”?
在我的代码中,我使用了一个宏,它应该生成一个日志条目,或者它不应该根据一些编译标志:
#ifdef SOMETHING
#define LOG(a) printf ("%s", a)
#else
#define LOG(a) while (0) {}
#endif
Run Code Online (Sandbox Code Playgroud)
这段代码运行良好,但是当我查看 Internet 时,我只看到有人在使用
#define LOG(a) do {} while (0)
Run Code Online (Sandbox Code Playgroud)
代替
#define LOG(a) while (0) {}
Run Code Online (Sandbox Code Playgroud)
这两种方法等价吗?我应该更喜欢一个吗?
while-loop ×10
loops ×4
c ×3
python ×3
c++ ×2
bash ×1
break ×1
comparison ×1
continue ×1
counter ×1
declare ×1
do-while ×1
if-statement ×1
macros ×1
python-3.x ×1
smalltalk ×1
typeset ×1