dimanche 27 septembre 2020

php if else condition in variable as string [duplicate]

I have if else condition as string like $cond = '40 < 50 and 60 > 70'; how can I execute it in PHP with out exec. if ($cond) not working as it just pass if variable exists or not. Thank you

What is the problem with my if statement? (java) [closed]

Spent so long trying to figure out what's wrong, I am new to Java and basically a beginner programmer, making the answer simple for me to understand will be greatly helpful. Thank you.

import java.util.Scanner;

public class CheckingTheAge {

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

        System.out.println("How old are you?");
        int age = Integer.valueOf(scanner.nextLine());
        
        if ( age => 0 && age =< 120) {
            System.out.println("OK");   
        } else {
            System.out.println("Impossible!")
        }
    }
}

How to keep asking user to input until condition is satisfied in C?

This is small C program and I am trying to validate the user input. I want user to enter 3 values. Condition is that all 3 inputs should not be of same value. So how to loop the user input until condition is satisfied(True). Here is the code. Help me out, I am new to Programming, Thanks. :)

#include<stdio.h>

int main()
{
    int u1,u2,u3;
    
    printf("Enter 3 Numbers : ");  //Printing
    scanf("%d %d %d",&u1,&u2,&u3); //Asking for Input
    
    if(u1==u2 || u2==u3 || u3==u1)       //This is the condition
    {
        printf("Condition is not Satisfied !");      
    }
}

So how do I loop it. Thank You.

for loop desired instead of nested if statements

I am building a website that does has a chat component to it. The code below receives from a stored procedure a list of messages with a lots of different paramaters. 1 of those is if a message is in reply to another, and if that is the case, duplicate the message that is being replied to over the message answer. If the message that was being replied to was also an answer to a previous message do the same ect. Now my issue is that I have not been able to figure out how to automate this part of the code without nesting if into one another until a point where I hope users won't reply in the same chain anymore.

  • To rephrase it, I go in a list in inverse order and check if the ReplyingTo is not null.
  • I then copy the row that has the same ID and ReplyingTo 1 row higher than the current row.
  • I then confirm that this new row has a ReplyingTo
  • If it does I copy that object 2 row higher than the current one.
  • and I would continue this way until I reached a certain point that the users would not reach.

If anyone got an idea on how to proceed I would be highly gracious. I have put an example of the type of data that would be given to this function below.

             for (int i = publicChatCountList.Count-1 ; i > -1; i--)
                {
                    if (publicChatCountList[i].ReplyingTo.HasValue)
                    {
                        Chat_Dto chatItem = new Chat_Dto();
                        long? ReplyingToId = publicChatCountList[i].ReplyingTo;
                        chatItem = publicChatCountList.Find(x => x.Id == ReplyingToId);
                        publicChatCountList.Insert(i+1, new Chat_Dto() {Text = chatItem.Text, IsPublic = chatItem.IsPublic, IsApproved = chatItem.IsApproved, ReplyingTo = chatItem.ReplyingTo });
                        publicChatCountList[i+1].Duplicate = true;

                        if (chatItem.ReplyingTo.HasValue)
                        {
                            Chat_Dto chatItem2 = new Chat_Dto();
                            long? ReplyingToId2 = chatItem.ReplyingTo;
                            chatItem2 = publicChatCountList.Find(x => x.Id == ReplyingToId2);
                            publicChatCountList.Insert(i + 2, new Chat_Dto() { Text = chatItem2.Text, IsPublic = chatItem2.IsPublic, IsApproved = chatItem2.IsApproved, ReplyingTo = chatItem2.ReplyingTo });
                            publicChatCountList[i + 2].Duplicate = true;
                        }
                    }
                }

enter image description here

VBA Sort ignored inside ElseIf

Could anyone please explain to me why it is that the line below that is trying to filter my data by E1 will not work in the first location (see "<<< 1st Location"), but it works fine in the second location (see "<<< 2nd Location"). No error thrown for the first location, it just seems to skip it.

Private Sub CommandButton31_Click()

Call CreateDataSheet

If ToggleButtonFrontTeam.Value = False And ComboBox1.Value = "Designer" Then
    Call FilterFrontTeamSortDesigner
    Sheets("Data_Sheet").Range("A2:I10000").Sort Key1:=Range("E1"), Order1:=xlAscending, Header:=xlNo   '<<< 1st Location
ElseIf ToggleButtonMidTeam.Value = False And ComboBox1.Value = "Designer" Then
    Call FilterMidTeamSortDesigner

ElseIf ToggleButtonRearTeam.Value = False And ComboBox1.Value = "Designer" Then
    Call FilterRearTeamSortDesigner

Else
    Unload Me

End If

Sheets("Data_Sheet").Range("A2:I10000").Sort Key1:=Range("E1"), Order1:=xlAscending, Header:=xlNo    '<<< 2nd Location

Unload Me
End Sub

Python 3 recursion [closed]

I’m trying to express the recursion z_n= z_(n-1)^2 + c. Where z0 and c are complex numbers. So far I have:

for n in range(1,N):
     z=n**2+c

I know n does not represent z_(n-1) but I can’t figure out what does to make this work.

How can I check if a certain combination of values exists in a dictionary in a list?

I have a list of dictionary as follows:

knownShows = [
    {'Parsed Name': 'A', 'Parsed Season':'1', 'Override?': 'N', 'NewName': '', 'NewSeason': ''},
    {'Parsed Name': 'B', 'Parsed Season':'1', 'Override?': 'N', 'NewName': '', 'NewSeason': ''},
    {'Parsed Name': 'C', 'Parsed Season':'2', 'Override?': 'N', 'NewName': '', 'NewSeason': ''},
    {'Parsed Name': 'D', 'Parsed Season':'1', 'Override?': 'N', 'NewName': '', 'NewSeason': ''}
]

And I am using a python script to automatically add new dictionaries (show name with parsed season number) based on the episode name (eg "A - s01e02" becomes Parsed Name "A", and Parsed Season "1").

Is there any way to check if a certain combination of key/value pairs already exists in a dictionary in the list?

I was trying to use a modified version of this solution, turning it into

if not (any(d['Parsed Name'] == showName for d in knownShows) and any(d['Parsed Season'] == str(season) for d in knownShows)):

but this has started causing problems when there are multiple seasons of the same show in the list being parsed.

for example, I have an episode with the show/season combination of:

'Parsed Name' = "A"
'Parsed Season' = "2"

Since both: a show called 'A' and a season '2' already exist in the list, it isnt creating a new entry for Season 2 of A.

Is there any way to change the if statement to check for the combination of Show A and Season 2, and only turn False if this specific combination exists inside the same dictionary inside the list?