mercredi 26 septembre 2018

Caculate if a value is greater or less than some % of the next value

Let's assume I have a vector a=[1,2,3] b=[0.5,3,8] is there an if statement that can check if a(i) is greater or lower in the same time than b(i) in 5% . rather than check 5% up and 5% down. what is the code that will do it? thanks.

something like if(a(i)=abs(5% of b(i))) do so and so else break;

Where to put the if-condition inside a list comprehension?

I was given the function:

x**2 - 4*x + 6

and the task was to find the minimum integer values x between 0 and 10. I had to use a for loop:

for i in range(11):
    if 2*i-4==0:
        print("Minimum of the given function is:", i)

which gives me the correct answer 2.

Now I should translate that as a list comprehension, but I do not know where to put the if statement:

mylist = [2*i-4==0 for i in range(11)]
print(mylist)

Of course, as an output I get a true/false list, with the index 2 being the correct true. But How do I include the if in my list comprehension?

JavaScript if statement with multiple conditions and checking to see if input is empty

I have a JavaScript exercise where you have 3 different ways to search for a business listing. I'm trying to do an if statement that says if the 1st option is equal to 1 or higher (meaning not empty) and the other 2 search options are set to 0 (meaning empty) then something happens. However, the code isn't running my if statement. I know this because of me checking the console. What's wrong with my if statement?

JS

    <script>
    var listOfBusinesses = {
    "Food": "Leroy's Restaurant",
    "Hair": "Angie's Hair Salon",
    "Beauty": "Nora - MakeUp Artist",
    "Hardware": "Harry and Blu",
    "Food": "Elijah's Market",
    "Beauty": "Flair Nail Salon",
    "Retail": "Tiffany's Boutique",
    "Retail": "Charisma Home Decor",
    "Hair": "Lady Luck Salon",
    "Food": "Charlie's Produce"
    };

    function getBusinessResults(databaseOfBusinesses) {
    var searchByName = $("#inputByName").val();
    console.log(searchByName);
    var searchByFirstL = $("#inputFirstLetter").val();
    console.log(searchByFirstL);
    var searchByCategory = $("#inputByCategory").val();
    console.log(searchByCategory);
    event.preventDefault();

    if (searchByName > 0 && searchByFirstL == 0 && searchByCategory 
    == 0) {
    console.log("apple");
    for (i = 0; i < databaseOfBusinesses.length; i++) {
    if (searchByName == databaseOfBusinesses[i]) {
    console.log("apple");
    $("#businessResults").html("Yes " + searchByName + "is a 
    business listed with us.");
    } // line closes if statement 
    } // line closes for loop
    } // line closes if statement
    } // line closes function 
    </script>

HTML:

    <form action="javascript-exercise-15.html" method="post">
    <p id="byName">Search by Business Name</p>
    Business Name: <input id="inputByName" type="text" 
    name="businessName" value="">
    <br/><br/>
    <p id="byFirstL">Search by 1st Letter of Business Name</p>
    First Letter of Business Name: <input id="inputFirstLetter" 
    type="text" name="firstLetter" value="">
    <br/><br/>
    <p id="byCategory">Search by Category of Business</p>
    Category of Business: <input id="inputByCategory" type="text" 
    name="businessCategory" value="">
    <br/><br/></br/>
    <button class="businessBtn" 
    onclick="getBusinessResults(listOfBusinesses)">Search 
    Business</button>
    </form>
    <p id="businessResults"></p>

Why is my boolean expression not returning true and printing my statement? [duplicate]

This question already has an answer here:

package rockPaperScissors;

import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors {

public static int userScore = 0;
public static int compScore = 0;

public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);

    System.out.println("Welcome to Rock Paper Scissors Let's play best 2 out of 3!");
    System.out.println("Choose your weapon! Rock, Paper, or Scissors");
    String weaponChoice = keyboard.nextLine();

    if(weaponChoice.equals("Rock")) {
        System.out.println("You Chose Rock");
    } else if(weaponChoice.equals("Paper")) {
        System.out.println("You Chose Paper");
    } else if(weaponChoice.equals("Scissors")) {
        System.out.println("You chose Scissors");
    } else {
        System.out.println("That's not a valid answer the computer gets a point!");
        compScore++;
    }

    System.out.println("The computer chose " + getComputerChoice());

if((getComputerChoice() == "Rock") && (weaponChoice == "Rock")) {
    System.out.println("It's a draw!");
}

}
public static String getComputerChoice() {
      String[] choices = {"Rock", "Paper", "Scissors"};
      int randomNumber = (int) Math.floor(Math.random()*3);
      return choices[randomNumber];
    }
}

The user inputs Rock and when the computer randomly generates Rock it should match and be true and then print out It's a draw. It's not printing out so it's somehow returning False. I tried to change the && to || but then it was returning True even when the weaponChoice and getComputerChoice() are different.

I also tried this code

if((getComputerChoice() == weaponChoice)) {
    System.out.println("It's a draw!");
    }

It still won't print anything

I also tried

if(getComputerChoice().equals(weaponChoice)) {
    System.out.println("It's a draw!");
    }

Still nothing

Sumif and IF, to add up one column and compare it to another column

I have two lists that I want to compare to see if they match, but in one list the numbers are broken down into individual lots so I need to sum them first to make sure they match the other list which only shows the total amount.

Here's an example:

5 ABC 18 ABC 6 ABC 7 ABC 1 CDE 8 CDE 5 CDE 2 CDE

So I want to make sure that the sum of the ABC and CDE on the left matches the total amount of ABC and CDE on the right. I can do this using multiple columns, but I am trying for a more...elegant way (one nested formula).

Are multiple 'IF Statements' correct to use?

I have a two column page design in WordPress.

I would like to display a different widget based upon the allocated WordPress category in the right hand side column using a functions command.

My question is this: is my approach the 'correct method?' I have 3 sets of arrays in an "IF Statement"

I should add that it works!

But - I want to make sure that it is correctly done:

function my_custom_sidebar_display( $sidebar ) {
    // Return a different sidebar for different categories
    if ( in_category(array('Apples','Pears','Peaches')) ) {
        return 'sidebar-fruit';
    }
    if ( in_category(array('potatoes','carrots','celery')) ) {
        return 'sidebar-vegetables';
    }
  }
    if ( in_category(array('monkeys','rhino','cheetah')) ) {
        return 'sidebar-animals';
    }
    // Return theme defined sidebar area
    else {
        return $sidebar;
    }
}
add_filter( 'ocean_get_sidebar', 'my_custom_sidebar_display' );

windows command skipping problems

I've been writing this code to help manage my emulator roms (and offload them to drives when sharing with friends or on the go) whilst keeping my desktop clean (I know there are better ways but I thought it would be fun). I have isolated the problem to the :GBDBZ section it always skips straight to the pause. it is still in development and I can't seem to work this out any help will be greatly appreciated. (and yes some of the capitalisation sucks

Full Code here https://pastebin.com/DkeAKkkW

Troublesome code here :GBDBZ

cls
Title Dragonball Z
echo Please type the Title For Your Genre
more "%USERPROFILE%\Documents\ROMS\GB\DRAGONBALL Z\Titles.txt"
SET /P Title=:
IF "Title"=="Buu's Fury" GOTO TC1
IF "Title"=="Buus Fury" GOTO TC1
IF "Title"=="buu's fury" GOTO TC1
IF "Title"=="Buu'sFury" GOTO TC1
IF "Title"=="buu'sfury" GOTO TC1
IF "Title"=="buus fury" GOTO TC1
IF "Title"=="Buusfury" GOTO TC1
IF "Title"=="buusfury" GOTO TC1
IF "Title"=="BUU'S FURY" GOTO TC1
IF "Title"=="BUU'SFURY" GOTO TC1
IF "Title"=="BUUS FURY" GOTO TC1
IF "Title"=="BUUSFURY" GOTO TC1
IF "Title"=="Super Sonic Warriors" GOTO TC2
IF "Title"=="SuperSonicWarriors" GOTO TC2
IF "Title"=="super sonic warriors" GOTO TC2
IF "Title"=="supersonicwarrios" GOTO TC2
IF "Title"=="Super Sonic Warriors" GOTO TC2
IF "Title"=="SupersonicWarriors" GOTO TC2
IF "Title"=="Supersonicwarriors" GOTO TC2
IF "Title"=="Taiketsu" GOTO TC3
IF "Title"=="taiketsu" GOTO TC3
IF "Title"=="TAIKETSU" GOTO TC3
IF "Title"=="The Legacy of Goku" GOTO TC4
IF "Title"=="TheLegacyofGoku" GOTO TC4
IF "Title"=="the legacy of goku" GOTO TC4
IF "Title"=="Thelegacyofgoku" GOTO TC4
IF "Title"=="The Legacy Of Goku" GOTO TC4
IF "Title"=="The legacy of goku" GOTO TC4
IF "Title"=="The Legacy of Goku" GOTO TC4
IF "Title"=="THE LEGACY OF GOKU" GOTO TC4
IF "Title"=="THELEGACYOFGOKU" GOTO TC4
IF "Title"=="The Legacy of Goku2" GOTO TC5
IF "Title"=="TheLegacyofGoku2" GOTO TC5
IF "Title"=="the legacy of goku2" GOTO TC5
IF "Title"=="Thelegacyofgoku2" GOTO TC5
IF "Title"=="The Legacy Of Goku2" GOTO TC5
IF "Title"=="The legacy of goku2" GOTO TC5
IF "Title"=="The Legacy of Goku2" GOTO TC5
IF "Title"=="THE LEGACY OF GOKU2" GOTO TC5
IF "Title"=="The Legacy of Goku 2"GOTO TC5
IF "Title"=="TheLegacyofGoku 2" GOTO TC5
IF "Title"=="the legacy of goku 2" GOTO TC5
IF "Title"=="Thelegacyofgoku 2" GOTO TC5
IF "Title"=="The Legacy Of Goku 2" GOTO TC5
IF "Title"=="The legacy of goku 2" GOTO TC5
IF "Title"=="The Legacy of Goku 2" GOTO TC5
IF "Title"=="The Legacy Of Goku 2" GOTO TC5
IF "Title"=="THE LEGACY OF GOKU 2" GOTO TC5
pause