mercredi 8 décembre 2021

UI Button "if" statement in swift

when I type the code in, there is an error saying this:

picture of the error: https://i.stack.imgur.com/ixFaM.png

How can I fix it?

 @IBAction func nextQuestionButton(_ sender: Any) {
        if (nextQuestionButton.isSelected == true) {
            
        }

How do I write a Python Function to display a message to indicate the progress of an operation [closed]

The function should display a message in the following format: '{operation} {status}.'

Where {operation} is the value of the parameter passed to this function
and
{status} is 'has started' if the value of the parameter 'value' is 0
{status} is 'is in progress ({value}% completed)' if the value of the parameter 'value' is between,
but not including, 0 and 100
{status} is 'has completed' if the value of the parameter 'value' is 100

R: unexpected behaviour adding two if(){}else{} constructs

Consider the following R input:

if(TRUE){1}else{0} + if(TRUE){1}else{0}

The result is 1, but I was expecting 2. If I enclose each if-else statement in parentheses,

(if(TRUE){1}else{0}) + (if(TRUE){1}else{0})

then the result is 2.

Can someone explain this behaviour?

Change elevated button color via radio buttons in flutter

I want to change the Elevated button color when I press the radio buttons. 1.button -> red, 2.button -> yellow, 3.button -> green. In the Elevated.stylefrom if condition did not work. Just ternary condition works but it is only for one condition. I want to add 3 conditions. I hope it was clear.

Or do I need to create a model for this?

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:task_shopping_app/const/const.dart';
import 'package:task_shopping_app/screens/city_input_screen.dart';
import 'package:task_shopping_app/screens/weather.dart';

class RadioButton extends StatefulWidget {
  @override
  _RadioButtonState createState() => _RadioButtonState();
}

class _RadioButtonState extends State<RadioButton> {
  int selectedValue = 0;
  final enteredCityInfo = TextEditingController();
  String name = '';
  // if selectedValue and group value matches then radio button will be selected.
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          ButtonBar(
            alignment: MainAxisAlignment.center,
            children: <Widget>[
              Radio<int>(
                  value: 1,
                  groupValue: selectedValue,
                  onChanged: (value) => setState(() {
                        selectedValue = value!;
                        print(selectedValue);
                      })),
              Radio<int>(
                  value: 2,
                  groupValue: selectedValue,
                  onChanged: (value) => setState(() {
                        selectedValue = value!;
                        print(selectedValue);
                      })),
              Radio<int>(
                  value: 3,
                  groupValue: selectedValue,
                  onChanged: (value) => setState(() {
                        selectedValue = value!;
                        print(selectedValue);
                      })),
            ],
          ),
          Padding(
            padding: const EdgeInsets.all(25.0),
            child: TextField(
              controller: enteredCityInfo,
            ),
          ),
          ElevatedButton(
            onPressed: () {
              setState(() {
                name = enteredCityInfo.text;
                //Here we want to see user entry for the text field area in the debug console.
                print(name);
                // Get.to(() => WeatherScreen());
              });
            },
            child: Text('Create'),
            style: ElevatedButton.styleFrom(
              primary: selectedValue == 1 ? Colors.red : Colors.yellow,
            ),
          )
        ],
      ),
    );
  }
}

enter code here

C++ name format [closed]

I am new to C++ and would appreciate some guidance. Before I reveal the problem, let me emphatically state that I am looking for GUIDANCE, not an answer; having the answer given to me will not benefit me any! I know other people have asked similar questions on here, but the answers given included coding to which I have not been exposed yet- I'm not trying just to pass the class, I am taking this course to actually learn C++. Ok, here are the instructions:

Write a program whose input is:

firstName middleName lastName

and whose output is:

lastName, firstInitial.middleInitial.

My code is:

if (middleName.size() == 0 ) {
    cout << lastName << ", " << firstName[0] << "." << endl; }
else {
    cout << lastName << ", " << firstName[0] << "." << middleName[0] << "." << endl; }

I have the closing } and return 0; but didn't copy them. It works as expected when there is a middle name, but if there's not then it outputs this:

, t.d

My thinking was that if the middle name has no size, then it would output the last name and middle initial, but it does not. I tried outputting middleName.size() and keep getting zero, even if there is a middle name.

I appreciate any guidance, and know this is a long post, but I wanted to give as much info as I could.

mardi 7 décembre 2021

if else condition true it will run until it doesn't false, but when else condition is true it will run continuously until when it false

I have If - else condition,

High = [18365.5, 18979.25, 19297.4, 19874.8, 20288.0, 20504.65, 20398.2] 

Low = [17855.5, 18265.0, 18822.55, 18742.15, 19492.55, 20055.55, 20131.25] 

Close = [18317.05, 18969.95, 18857.6, 19804.0, 20260.15, 20285.0, 20215.7]

length = len(Close) - 1

i = 0
a = 1
Trend = ["No Trend"]
Difference = ["No Trend"]
while i<length:
    if Close[a] > Low[i]:
        trend = "Long"
        Trend.append(trend)
        difference = Close[a] - Low[i]
        Difference.append(difference)
    elif Close[a] < High[i]:
        trend = "Short"
        Trend.append(trend)
        difference = Close[a] - High[i]
        Difference.append(difference)
    i = i + 1
    a = a + 1
df = pd.DataFrame(list(zip(High, Low, Close, Difference, Trend, From_date, End_date)),
               columns =['High', 'Low', 'Close', 'Difference', 'Trend', 'From_date', 'End_date'])
display(df)

So i want if Close[a] > Low[i] condition is true so it will run continuously until it doesn't false, and when if condition will false so else Close[a] < High[i] condition start, so it will run continuously unitll it will not false.

I am showing you the below data frame, which will give you a clear-cut idea. enter image description here

In this Dataframe there are three columns which are High, Low, Close, and the rest of the columns are made by these three column.

So in if - condition is true so it's print "Long" continuously until It doesn't false, but when else condition start so else condition should run, and start checking this condition Close[a] < High[i]. until it doesn't false.

I'm trying my best to explain my question And Sorry, if my explanation is not good.

SQL: Is there a better way than "COALESCE on two selects" to find the first non-null result in an OR clause?

Let's say I have this table:

ID LANG NAME DEFAULT
1 ENG Cinderella false
1 ENG The Ash Bride false
1 FRE Cendrillon true
1 GER Aschenputtel false

("Ash bride" is just fabrication that the same ID can have several names in the same language) The SQL query should return the name in the wanted language, if it doesn't exist, the default language.

So a search for the book title if your settings are in German (GER), the result should be "Aschenputtel", but if your settings are Spanish, they should return "Cendrillon".

This question brings up the same issue, but the answer suggests a double join through the name list, one for "lang='[preferred]'" and one for the default value, with a COALESCE to find the first non-null result. I am worried this would cause performance issues if the names list is long, when there cannot be a primary key (as there can be many names per language), and the question is quite old, so wonder if there is a method more along the likes of

SELECT NAME WHERE ID=1 and (LANG='SPA' OR DEFAULT=true)

and return the first non-null result of the OR-clause. Ideally, something like:

(not functional)
SELECT COALESCE(SELECT NAME WHERE ID=1 and (LANG='SPA' OR DEFAULT=true));

Anything? Or is a coalesce on a double select the only answer?