vendredi 1 mars 2019

Why am I getting this 'can't assign to operator error?' [on hold]

I'm working on a project for school. I have to write a small text adventure game however my code has suddenly stopped working. when I try to run the code it highlights 'spouse = wife' and then gives an error saying 'can't assign to operator' How do I fix this and what is going wrong here? It was working before.

print("You wake up in the middle of nowhere feeling dizzy and confused. You don't remember who you are or how you got here.")
    option_1 = input("do you want to look for clues? >")
    if option_1 == 'yes' or option_1=='Yes' or option_1 == 'Y' or option_1=='y':
        print("you look around you but it is snowing and you can't see very far. You see an object in the distance")
        option_2=input("do you investigate the object? >")
        if option_2=='yes' or option_2=='Yes' or option_2== 'Y'  or option_2== 'y':
            print("you found a backpack. Maybe it's yours.")
            option_3=input("would you like to open the backpack? >")
            if option_3 == 'Yes' or option_3 =='yes' or option_3 == 'y' or option_3 == 'Y':
                print ("The contents of the backpack jog some of your memory. It's yours!")
                name_f = input('What is your first name?')
                name_l = input("What is your last name?")
                gender = input("what is your gender?")
                if gender == 'male' or gender == 'Male' or gender == 'M' or gender == 'm':
                    spouse = 'wife' and spouse_name = 'Georgia' and pronoun = 'he'
                if gender == 'female' or gender == 'Female' or gender == 'F' or gender == 'f':
                    spouse = 'husband' and spouse-name = 'George' and pronoun = 'she'
                print("you find a letter from your", spouse, "it is not addressed to you:")
                print("Dear Mr. Adams"+",")
                print("I hope this finds you keeping well. I am afraid I won't be able to attend our meetings anymore. I hope I haven't disappointed you but", name_f, "has been asking too many questions and i'm worried that", pronoun+"'s", "getting suspicious")
                print("yours,", spouse_name, name_l)
            else:
                print("you do not survive: game over")
    else:
        print("you do not survive")

TYPO3, Fluid template. Display a div if the date of today is between 05/01 and 10/01

I want to display a div if the date of today is between "05/01" and "10/01". Could someone please help me with it? :)

I could only display it when the date is between "01/01" and "10/01" by writing this code:

<f:if condition="{f:format.date(date: '10/01' format: 'm/d')} < {f:format.date(date: 'now', format: 'm/d')}">
                <f:then><div>The Store is closed.</div></f:then>
                <f:else><div>The Store is open!</div></f:else>

Many thanks in advance!

Pythonic way of Refactoring longer "One line" if-condition-assignment ( ternary If )

My current code uses tenary assignments One line if-condition-assignment, but with more verbose identifyers it is easily passing line length limits.

Since I am not yet into pythonic coding, I would be glad to see some refactoring suggestions.

    for label in range(num_labels):
        d_tresh = drop_treshold[label] if type(drop_treshold) == numpy.ndarray) else drop_treshold     
        r_tresh1 = relabel_treshold1[label] if type(relabel_treshold1) == numpy.ndarray else relabel_treshold1
        r_tresh2 = relabel_treshold2[label] if type(relabel_treshold2) == numpy.ndarray else relabel_treshold2

Using locally short variable names seems part of solution, but I like to have more explanatory function arguments. Hm. So dramatically shortening function argument names results in (for me) unreadable code.

for l in range(n_labels):
    t0 = d_t[l] if type(d_t) == numpy.ndarray) else d_t     
    t1 = r_t1[l] if type(r_t1) == numpy.ndarray else r_t1
    t2 = r_t2[l] if type(r_t2) == numpy.ndarray else r_t1

So shall I resort to multi line if - else assignments? It will stretch and bloat the simple logic dramatically.

for label in range(num_labels):
    if type(drop_treshold) == numpy.ndarray):
        d_tresh = drop_treshold[label]
    else
        drop_treshold     

    if type(relabel_treshold1) == numpy.ndarray:
        r_tresh1 = relabel_treshold1[label] 
    else
        relabel_treshold1

    if type(relabel_treshold2) == numpy.ndarray:
        r_tresh2 = relabel_treshold2[label] 
    else
        relabel_treshold2

(Surely I (sh/)could also refactor the whole code around the shown example... This example snippet comes from function with arguments, which could be scalar float/int or 1D numpy.array. If it is an array it will apply each item to each label, just being plain scalar it will apply it globally to all labels) But here again how is the pythonic way? When to start to refactor more exhaustively and when to stay put - because it works?

dataGridView column referencing and nested if statements with CellContentDoubleClick event c#

Hi so i see a lot of posts re: cell referencing in a DGV and nested if statements. The post have got me soo far i am very nearly there or maybe not... i am hoping for some help and open to suggestions.

very simply i need to be able to double click on a certain cells in dgv, on double clicking the cell, if that cell is in certain column it applies a 1 or 0 to its relating column.

So, doubling clicking a cell in column 2 applies a figure one or zero depending to the same row but column 5.

so,column 2 relates to 5
      6 relates to 9
      10 relates to 13
      14 relates to 17
      18 relates to 21
      22 relates to 25

here is what i have so far..i have messed about alot and have taken it so far however i cannot get it to work independently. so, if i double click all columns change not the relating column. at present this doesn’t work. any help would be welcomed.

        private void dataGridViewAcorn_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
    {

        commandBuilder = new SqlCommandBuilder(dataAdapter);
        dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();//get the update command



        string HW_A = dataGridViewAcorn.CurrentRow.Cells[5].Value.ToString();
        string Crwn_A = dataGridViewAcorn.CurrentRow.Cells[9].Value.ToString();
        string HB_A = dataGridViewAcorn.CurrentRow.Cells[13].Value.ToString();
        string OV_A = dataGridViewAcorn.CurrentRow.Cells[17].Value.ToString();
        string Acorn_A = dataGridViewAcorn.CurrentRow.Cells[21].Value.ToString();
        string Brn_A = dataGridViewAcorn.CurrentRow.Cells[25].Value.ToString();

        int columnIndex = dataGridViewAcorn.CurrentCell.ColumnIndex;


        if (columnIndex == 2)
        {
            if (HW_A == ("1"))

            {
                dataGridViewAcorn.CurrentRow.Cells[5].Value = 0;

            }
            else HW_A = ("0");

            {
                dataGridViewAcorn.CurrentRow.Cells[5].Value = 1;

            }


        }



        /*
        System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
        messageBoxCS.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex);
        messageBoxCS.AppendLine();
        messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex);
        messageBoxCS.AppendLine();
        MessageBox.Show(messageBoxCS.ToString(), "CellConentDoubleClick Event");

        */

        dataGridViewAcorn.DataSource = bindingSourceAcorn;
        bindingSourceAcorn.EndEdit();// updates table in memory 
        dataAdapter.Update(table);//actually the data base 
                                  //MessageBox.Show("Update Successful!");




    }

mock data for this.$el for unit this with karma

I want to create a unit test for the following code with Karma.

       if (!this.$el.contains(e.target)) {
            this.isActive = false;
        }

How can I mock the data from the if statement to get the return back?

   describe('removeClass()', () => {
        it('should return false', () => {
            vm.removeClass();
            expect(vm.isActive).toBe(false);
        });
    });

if statements not working correctly [C++]

I am writing code to check if a sentence is a palindrome. I feel like my logic is correct, but the if statements for check the reverse of the string do not seem to be working. I have tried many solutions online but still nothing. Every string is seen as not a palindrome. I feel the error is at (sentence == reverse):

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])  {

while (true) {
  string sentence;
  string reverse = "";

  cout << "Enter a sentence below to check (-1 to end):" << endl;
  getline(cin, sentence);

  if (sentence == "q") {
    break;
  }

  for (int i = sentence.length(); i >= 0; i-- ) {
    reverse += sentence[i];
  }

  cout << sentence << " reversed is: " << "[" << reverse << "]" << endl;

  if (sentence == reverse) {
      cout << sentence << " is a palindrome" << endl;
  } else {
    cout << sentence << " is not a palindrome" << endl;
  }
  cout << endl;
}

}

Any help would be greatly appreciated.

Multiple If statement logic issue

I'm pretty new to jQuery and I have a bit of an issue with some jQuery logic I'm making so I've included the code below. I have the first if statement checking the screen resolution, the 2nd if statement is checking how many list items there are and to only run if 1 or more and the final if statement making sure that only 1 instance of the append is running as it's inside an AJAX request so had issues with multiple instance being output.

Any suggestions as to where I've gone wrong? Any help would be awesome, thank you :)

HTML:

<ul class="swatches color clearfix">
    <li class="selectable">
        <span class="swatchanchor js-swatchanchor js-colorswatch">
            List Item 1
        </span>
    </li>

    <li class="selectable">
        <span class="swatchanchor js-swatchanchor js-colorswatch">
            List Item 2
        </span>
    </li>
</ul>

jQuery

if($(window).width() >= 1358){
    var $lis = $('ul.swatches.color li');
    var $jsColorMsgCheck = $('.jsColorMsgError');



    if ($lis.length > 1) {
      if ($jsColorMsgCheck.length) {
        $(".swatches.color").parent().append($('<div class="jsColorMsgError">PLEASE SELECT A COLOUR</div>'));
      }
    }
}