dimanche 2 juillet 2017

Python recursive function call with if statement

I have a question regarding function-calls using if-statements and recursion. I am a bit confused because python seems to jump into the if statements block even if my function returns "False"

Here is an example:

1    def function_1:
2       if function_2:
3           #do something
4           if x<y:
5               function_1(#different parameters)
6           if x>y:
7               function_1(#different parameters)

My function_2 returns "False" but python continues the code on line 5 for example. Can anyone explain this behavior? Thanks in advance for any answers.

samedi 1 juillet 2017

Bash script runs but fails every if statement - help on why?

Working on a simple organizational script to copy data to a new destination. The script runs without generating any errors, but no data actually gets moved. Would love any insight on why this might be! Thx :)

cd $fp

files=(ls)
ls
for file in $(ls)
do
    echo '***moving fldr***'
    cd $fp/$file/mydir
    if [ -d fldr ] ; then
    cp -R fldr $dp/element/ ;
    mv fldr fldr_$file ;
    tar -cvzf fldr_$file.tgz fldr_file ;
    echo '***moved fldr***'
else
    echo '***couldnt move fldr***'
fi
if [ -d dir ] ; then
    echo '***moving dir***'
    cp -R dir $dp/element2/ ;
    mv dir dir_$file ;
    tar -cvzf dir_$file.tgz dir_file ;
    echo '***moved dir***'
else
    echo '***couldnt move dir***'
fi
done

how do i stop a number from being lower in an if statement

please dont mark me down for this one guys as im a bit un sure how to even ask the question.

in my app i have a reward system. it uses firebase database to release the rewards.

for example if a user downloads 2 items and watches a short advert it registers there userid and the number 1 to the database. my app then receives that number and adds the relevant reward. but lets say i add the number 2 manually to my database for a prize for a competition or something similar.. it does add the reward. but then if they download another item it cancels the reward and goes back to the number set by the offical counting method i have set up..

is there a way to say if the number is higher than the one in the offical counting method do nothing? i know this is confusing lol and im sorry in advance

this is my simple code

 }else
    if (counter == 1) {
        mRewards.mstreaming.setBackground( mcontext.getResources().getDrawable(R.drawable.buttonbkground2) );

if it already = 2 i dont want it to go back to the above

PHP/MySql if-operator within select statement

I have database with several tables, all have one column with same name. I want to fetch data from this column that way so when it's fetched from particular table ("countries"), it has string append, otherwise data is simply fetched. Here is my method

public function getInfo($table, $id) {
    $operate = $this->pdo->prepare("select if({$table}=='countries', 'concat('capital', city)', 'city') city from {$table} where id= {$id}");
        $operate->execute();

        return $operate->fetchObject();
    }

I have several methods within a class and everything works fine. This one also works without if-statement, the problem appears to be with this expression: {$table}=='countries'. However, I couldn't find where my mistake is. I'm new to php and would be glad to know what is the problem with this expression and how shall I get around it.

JAVA Read Simple Key Press?

I want to read a simple a key - how can I add this? Please can anyone help?

public class Test {

public static void main(String[] args) throws IOException{


    SetUp_JFrame SetUp_JFrame =new SetUp_JFrame();
    SetUp_JFrame.PART1(); 

    READ_KEY READ_KEY =new READ_KEY();
    for(;;) { 
       READ_KEY.PART2();  
            }


}}
class SetUp_JFrame {

public JFrame f; // `f` is now an instance field of the SetUp class

void PART1()throws IOException {

    f = new JFrame();

    f.setTitle("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //    System.out.println(f);

    // SetUp g =new SetUp();
    // You don't need to create a new SetUp object, you can directly access 'f' here.
    f.setSize(128,128);
    f.setLocation(10,10);
    f.setVisible(true);

   //  System.out.println(f);
}
}

class READ_KEY {
  void PART2() {

    A = KeyPress
       System.out.println("You Pressed Key "+A);
    }
    }

stackoverflow asking for more detail not sure what more I can say? in Basic you would use something like
DO
A=Inkey$
Print A
Loop

how to set two variables for single IF statement

Hi everyone :) english isn't my first language so please excuse any mistakes

my question is how to set two answers for Choice1 in the following code, if i enter G or Google it redirects to google.com and Y or Yahoo it redirects to yahoo.com

 var CHOICE1 = prompt("Enter Your Choice Google/Yahoo: ");

    if ( CHOICE1 == 'Google' && 'G' ){
        iimPlay('CODE:'+'SET !TIMEOUT_PAGE 100'+'\nURL GOTO=www.google.com');}

    else if ( CHOICE1 == 'Yahoo' && 'Y' ){
        iimPlay('CODE:'+'SET !TIMEOUT_PAGE 100'+'\nURL GOTO=www.yahoo.com');}

I don't have a great knowledge in javascript/programming. I searched Google and tried some of the suggestions but none have worked.

So, whats wrong in this code, and how can I fix it? and thanks in advance

MS Access 2003 Is it possible to get the following result in the report?

In MS Access 2003 I have a report with 4 possible scenarios

1.possible scenario: If (Me.Ocjena1 = 2 Or 3 Or 4 Or 5) And (Me.Ocjena2 = 1) And IsNull(Me.Ocjena3) Then Me.Konacna_ocjena = 1 End If

2.possible scenario If (Me.Ocjena1 = 2 Or 3 Or 4 Or 5) And (Me.Ocjena2 = 2 Or 3 Or 4 Or 5) And IsNull(Me.Ocjena3) Then Me.Konacna_ocjena = (Me.Ocjena1+Me.Ocjena2) /2 End If

3.possible scenario If (Me.Ocjena1 = 2 Or 3 Or 4 Or 5) And l(Me.Ocjena3 =1) and (Me.Ocjena3 = 2 Or 3 Or 4 Or 5) Then Me.Konacna_ocjena = (me.Ocjena1+me.Ocjena3) /3 End If

4.possible scenario If (Me.Ocjena1 = 2 Or 3 Or 4 Or 5) And IsNull(Me.Ocjena2) And IsNull(Me.Ocjena3) Then Me.Konacna_ocjena = Me.Ocjena1 End If

Sometimes is included all 4 scenarios. With this code work max 2 scenarios but 2 rest not working... Where am I wrong?