dimanche 27 août 2017

swift if statement, condition will never be executed

I thought I was good with if statements but apparently Im still missing something. In the following the timer.invalidate() line returns a "Will never be executed". As far as I can tell my syntax is correct.. xcode 9 beta6

@IBAction func button(_ sender: Any) {

        let timer = Timer.scheduledTimer(timeInterval:0.2 , target: self, selector: #selector(ViewController.imageSwitch) , userInfo: nil, repeats: true)

    var buttonState = false

    if buttonState == true {
        timer.invalidate()
        buttonState = false
    }
    if buttonState == false {
        timer.fire()
        buttonState = true
    }
}

samedi 26 août 2017

Why wrong results coming when using 'in' in if condition?

I have two dataframes df1 contains 100K rows and df2 contains 6 million rows. I want to fix values for 'SoftDel???' column in df1 when 'id' matches in df2. code is working but results are wrong.

I have completed this task using merge and results are satisfactory but want to know why below is producing wrong results?

for x, y in df1.iterrows():
if y['id'] in df2['id']: df1.loc[x,'SoftDel???'] = 'No'

Input 3 sides of triangle, determine if EQUILATERAL, ISOSCELES, or SCALENE; I tried the if-statement many times but its not working

/*The instruction is ask user to input 3 sides of triangle then determine if EQUILATERAL, ISOSCELES, or SCALENE; I tried the if-statement many times but its not working. */

:TRIANGLE
echo AREA OF TRIANGLE
echo Input First Side:
set /p a=
echo Input Second Side:
set /p b=
echo Input Third Side:
set /p c=
set E=EQUILATERAL
set I=ISOSCELES
set S=SCALENE
Pause
goto Top

Python 3 : Unexpected indent in 'if'

I am making a questioning program with python 3, I use this code

print ('how old are you?')
age = input ('age :')
if age < 18): print('Okay')

when i run it, there are a message said

if age < (18):
^
IndentationError: unexpected indent

what should i do?

How to insert combo box in if statement

i have a combo box with three options. A number is altered according to the choice. how do i insert this into an if statement. e.g if you choose option A (in combo box) then number = "a constant"

What step am I missing to check if value matches array element and print an alert using if/else

I'm trying to check user input against predetermined list of zipcodes. I've created one variable that represents the user input using document.getElementById("zipcode").value and set up my array of zipcodes to check against. This worked once but I think I had break; included in the if/else. What am I missing? The input box translates to a string so I made my array elements string too. I'm so confused.

<h2>Zipcode checker</h2>

<input id="zipcode" name="address-4" type=text maxlength="5" value="" pattern="[0-9]" required/>`
<button id="btn" value="submit" type="submit" onclick="myStuff()">Register</button>

Script:

var btnInput = document.getElementById("zipcode").value;
var acceptedZip = ["85392", "85340", "85393", "85353", "85341"];
function myStuff() {
    for (var i = 0; i < acceptedZip.length; i++) {
        if (acceptedZip[i] === btnInput) {
            alert("we got you boo");
         } 
         else {
            alert("sorry son");
        }
    }
}   

Add string to array if condition found using coalesce operator

I know I can test the condition and run the code like this:

if (scrapedElement.Contains(".html")
     string [] Test = new string[] { scrapedElement, string.empty }
else 
     string [] Test = new string[] { scrapedElement }

However, I want to do it in a single line if possible. Something similar to this (this is the full line of code that I want it to work in):

File.AppendAllLines(@"C:\Users\DJB\Documents\Visual Studio 2017\Projects\TempFiles\WebScraperExport.csv", new[] { (scrapedElement.Contains(".html") ? scrapedElement, string.Empty : scrapedElement)});

What I am doing is a web scraper that then saves the files in an excel file. For every element it finds that is a link, add a blank line after it, if not just add the element.