我有一个文件:
P 0.5 0.6 0.3
30 300
80 150
160 400
200 150
250 300
T
r 45 0 0
s 0.5 1.5 0 0
t 200 –150
.
.
.
Run Code Online (Sandbox Code Playgroud)
当我读到'P'时,我知道将会有3个花车.接下来是有限数量的X和Y坐标.数字会有所变化,直到达到"T",我必须承认.然后可能会有一个'r','s'或't'后跟一些值.
无论如何我知道如何识别'P'然后接收2个浮点数然后我知道我必须有一个while循环的X和Y坐标,当我到达'T'时它将停止.我不太了解C++使循环停止并识别'T'然后做其他事情.
一个例子来解释将不胜感激.提前致谢!
<if a == 5 && b < 4>
one
<else>
<if a != 5>
two
<else>
<if a == 5 || $b == 5>
three
</if>
</if>
</if>
Run Code Online (Sandbox Code Playgroud)
我怎么能从它得到一些变量:
[0] = "a == 5 && b < 4"
[1] = "one"
[2] = "a != 5"
[3] = "two"
[4] = "a == 5 || $b == 5"
[5] = "three"
Run Code Online (Sandbox Code Playgroud)
或者您如何建议在模板中创建条件?
嗯...你能告诉我为什么这样有效:
{if !$conta|contains:"word1" && ($product->id_category_default < 388 || $product->id_category_default > 475)}
Run Code Online (Sandbox Code Playgroud)
而这不是:
{if (!$conta|contains:"word1" || !$conta|contains:"word2") && ($product->id_category_default < 388 || $product->id_category_default > 475)}
Run Code Online (Sandbox Code Playgroud)
语法错误在哪里?
我想仅在今天的日期显示数据提供者中的数据.$ data-> timedate是约会日期.如果它等于当前日期,则显示它.以下代码不起作用.
//today appointments dataprovider
$taProvider=new CActiveDataProvider('Appointments',array(
'sort'=>array(
'defaultOrder'=>'datetime ASC',
),
'criteria'=>array(
'condition'=>'cId=:cId',
'params'=>array(':cId'=>Yii::app()->user->id),
'condition'=>$data->timedate = date('Y-m-d'),
),
));
Run Code Online (Sandbox Code Playgroud) 我正在写一个Python脚本,我有一个变量声明的问题,这是我的脚本的一部分:
if chromosome :
if chromosome.group(1) != '1' :
output.close()
print str(base)+" bases found in chromosome "+chr_name
chr_name = chromosome.group(1)
output = open(current_dir+"/"+name+"3/"+name+".chr"+chromosome.group(1)+".wig", "w")
output.write("fixedStep chrom=chr"+chromosome.group(1)+" start=1 step=1\n")
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我在关闭输出之前在代码中创建它,但事实上,这种情况永远不会发生,因为您无法在创建文件之前输入条件.
我可以做一些脏东西,在我的条件之前打开一个tmp文件,但那不是很优雅.所以我想知道是否有另一种解决方案让Python开心?
编辑:
if chromosome :
if chromosome.group(1) != '1' :
print str(base)+" bases found in chromosome "+chr_name
chr_name = chromosome.group(1)
with open(current_dir+"/"+name+"3/"+name+".chr"+chromosome.group(1)+".wig") as output:
output.write("fixedStep chrom=chr"+chromosome.group(1)+" start=1 step=1\n")
Run Code Online (Sandbox Code Playgroud)
EDIT2:
这是算法的概念,也许它可以帮助更好地理解问题:
for line in input do :
chromosome = re.search(something)
if chromosome :
if chromosome != '1' :
ouput.close()
output = open(file+chromosome) …Run Code Online (Sandbox Code Playgroud) 这样做是不好的做法:
Scanner scan = new Scanner(System.in);
if(scan.nextInt() == 5) { //testing if input is equal to 5
System.out.println("input equals 5");
}
Run Code Online (Sandbox Code Playgroud)
关于什么:
Scanner scan = new Scanner(System.in);
if(scan.nextInt() == scan.nextInt()) { //testing if two inputted ints are equal to each other
System.out.println("input1 equals input 2");
}
Run Code Online (Sandbox Code Playgroud)
我在某处读到这会导致"意外结果",但我不知道这意味着什么.我已经测试了这一点,并没有遇到任何意外的事情.
java conditional if-statement coding-style conditional-statements
当我遇到一些看起来像这样的代码时,我正在重构一些代码:
if( __some_bool__ != NULL ) {
.....do something......
}
Run Code Online (Sandbox Code Playgroud)
哪里__some_bool__是bool.我不是说了BOOL那是typedef在Windows头文件"d.
这绝对不是(编写本文的程序员)的意图.但是,在实际修复它之前,我想确保我没有破坏任何东西.
这将如何评估?不false== NULL?发生了什么样的胁迫?
我的html.erb 中有这样的脚本:
if(browser == "Firefox") {
$(".browser-warning").show();
}
else if(browser == "Safari") {
if(browser.version < 6) {
$(".browser-warning").show();
}
}
else if((BrowserDetect.browser != "Chrome") && (<%= params[:section_id].to_s %> != '')) {
console.log('yo');
<%= session[:is_chrome] = false %>
<%= Rails.logger.debug = "I made is_chrome false, wtf?" %>
}
else {
$(".browser-warning").show();
}
Run Code Online (Sandbox Code Playgroud)
我从 Chrome 浏览器运行这个脚本,条件返回false。
但是session[:is_chrome]总是变为 false 并且 Rails 记录器返回“我使 is_chrome 为 false,wtf?”。但。JS 控制台记录器不会在控制台中打印“yo”。为什么会这样,只有在 JS“if”语句为真时才定义会话值的正确方法是什么?
谢谢,所有。
我最近看到了一个我不明白的问题。这里您有:
x <- c(1,2,3,4,45,654,3,NA," ",8,5,64,54)
Run Code Online (Sandbox Code Playgroud)
而且||条件r不符合我的利益:识别NA和空白:
if(is.na(x) || x==" ") {...}
Run Code Online (Sandbox Code Playgroud)
我期望if函数返回,TRUE但是它会返回FALSE。有人可以在这里帮助我了解此问题吗?谢谢!
编辑:
抱歉,我打算在if语句中使用参数,因此长度应为1。|不适用于此处。
是否有更好的方法通过消除ifC语句中的重复条件来编写以下代码?
while (n < 0) {
printf("Enter a positive integer: ");
scanf("%d", &n);
if (n < 0) {
printf("Error: please enter a positive integer\n");
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
if-statement ×3
c++ ×2
php ×2
while-loop ×2
c ×1
coding-style ×1
conditional ×1
criteria ×1
dataprovider ×1
declaration ×1
file-io ×1
java ×1
javascript ×1
missing-data ×1
na ×1
nonblank ×1
operators ×1
python ×1
r ×1
ruby ×1
smarty ×1
templates ×1
visual-c++ ×1
yii ×1