mardi 1 octobre 2019

If statement recheck in a loop?

So I have a simple if function:

def function():
    if my_var is True:
       #run program

Im looking for some effective way to recheck this statement as frequently as possible.

I know I can make a loop to run this every second or even use:

while True:
    function()

but maybe there is a better solution for this.

Looping this will require the use of threading or multiprocesing in my case and I'd prefer to avoid that.

write a program that displays all the numbers in the range from 1 to 1000, which are divisible by 13 without a remainder, each number on a new line

Using the theoretical material above, the theory of loops, and the conditional if operator, write a program that displays all the numbers in the range from 1 to 1000, which are divisible by 13 without a remainder, each number on a new line.

You are not allowed to change line 3 with loop condition

Replacing Strings in Google Sheets from Dropdown List

how can I replace strings in Google Sheets? I have a dropdown list with let's say apple, banana and I want to replace the word with another word depending on the selection in the dropdown list. Let's say if I choose apple in the list I want to replace the string with stone, if it's banana I want to replace it with car. How can I do that?

Collecting same answer from different questions in one variable?

I am completely new to R, but running out of time here. In my dataset, I have people from several countries answering who they voted for last. People from different countries got different questions, so in each column, only the ones from the country have an answer, the rest is NA. I am trying to collect everyone who voted for a green party in one variable. So far I have succeeded in coding it into a separate dummy variable for each country using ifelse, but I cant seem to merge these variables. So now I have ie a variable for Germany, where a green vote in the german election is 1, and everyone else is 0. Same goes for France etc. But how can I collect all this information in just one variable?

Appreciate your help.

c++ : The if statement not functioning correctly and proceeds to Invalid output

Just started learning c++ and trying to make an automated ordering system but while trying to run before continuing working with it i'm encountering this problem :

#include <iostream>
using namespace std;

char acoustic, fender, hartwood, electric, gibson, ibanez, drums, pearl, 
roland, piano, casio;
char rolandpi, equip, string, headphone, amp, mixer, micro, tuner, pick, 
music, Yes, No;

int pay1 = 0, pay2 = 0;

int main()
{
    cout << "Welcome to the Music Shop" << endl <<endl;

    cout << "a. Acoustic Guitar" << endl;
    cout << "a.1 Fender Acoustic Guitar   - P6,900.00" << endl;
    cout << "a.2 Hartwood Acoustic Guitar - P6,300.00" << endl <<endl;

    cout << "b. Electric Guitar" << endl;
    cout << "b.1 Gibson Electric Guitar   -P8,500.00" << endl;
    cout << "b.2 Ibanez Electric Guitar   -P25,000.00" << endl <<endl;

    cout << "c. Drums" << endl;
    cout << "c.1 Pearl Drum Kits          -P27,000.00" << endl;
    cout << "c.2 Roland Electronic Drums  -P24,000.00" << endl <<endl;

    cout << "d. Piano" << endl;
    cout << "d.1 Casio Digital Piano      -P19,000.00" << endl;
    cout << "d.2 Roland Piano             -P120,000.00" << endl <<endl;

    cout << "e. Music Equipments" << endl;
    cout << "e.1 Guitar String            -P113.00" << endl;
    cout << "e.2 Headphones               -P1,600.00" << endl;
    cout << "e.3 Amplifier                -P2,800.00" << endl;
    cout << "e.4 Digital Mixer            -P4,750.00" << endl;
    cout << "e.4 Vocal Microphone         -P860.00" << endl;
    cout << "e.5 Guitar Tuner             -P537.00" << endl;
    cout << "e.6 Guitar Pick              -P360.00" << endl <<endl;

    cout << "Choose the music instrument or equipment you want to buy: ";
    cin >> music;

    switch (music)
    {
        case 'a':

        cout<< "Acoustic Guitar" << endl;
        cout<< "1. Fender Acoustic Guitar   - P6,900.00" << endl;
        cout<< "2. Hartwood Acoustic Guitar - P6,300.00" << endl <<endl;
        cout<<"Choose from the available Acoustic Guitars:";
        cin>>acoustic;

        if (acoustic == 1){
            cout<<"Enter your payment:";
            cin>>pay1;
            if (pay1=6900){
                cout<<"You have succesfully purchased Fender Acoustic Guitar"<<endl;
            }
                else if (pay1>6900){
                    pay1 -= 6900;
                    cout<<"Your change is:"<<pay1<<endl;
                }
                    else (pay1<6900);
                    {
                        cout<<"You do not have enough money"<<endl;
                    }
        }
        else if (acoustic == 2){
            cout<<"Enter your payment:";
            cin>>pay1;
            if (pay1=6300){
                cout<<"You have succesfully purchased Fender Acoustic Guitar"<<endl;
            }
                else if (pay1>6300){
                    pay1 -= 6300;
                    cout<<"Your change is:"<<pay1<<endl;
                }
                    else (pay1<6300);
                    {
                        cout<<"You do not have enough money"<<endl;
                    }
        }
        else {
            cout<<"Invalid"<<endl;
        }
    }
}

I already checked my if else statements and can't find whats wrong.

After inputting 1 or 2 from "Choose from the available Acoustic Guitars" it keeps proceeding to "invalid".

Why does my 'mailto' function not work after an if statement

I am writing a function that has to check 8 inputfields of a form. If all of them are filled in by the user, the 'mailto' function should open the email client. The function until now does all the stuff that is necessary, except for opening the email client. The if/else statements themselves work fine, as the alert boxes I put after those statements correspond correctly. The 'mailto' function works fine when I put it outside the if/else statements, but then it will open despite the fact that not all inputfields are filled in. Why does the email client not open after the if-statement, even though the alert box after the very same if-statement does show.

If-else statement in R to describe three different cases

What is an efficient way to describe three different cases for x<y, x>y and x=y? Here x and y are two numbers. I thought the following:

if (x<y) {
  ...
}
if (x>y) {
  ...
}
if (x=y) {
  ...
}

Maybe I could use ifelse statement?