dimanche 27 décembre 2020

Python Variable Understanding

I was writing this code and I can't seem to get it to work correctly. There's no Syntax errors so I'm clear on that. It just is not giving me the correct output I want.

Here's the code :

CLICK HERE FOR THE CODE IMAGE

This is the out put I get when x = 5 : Big! Done!

This is the output I get when x = 1 Small! Done!

This is what I get when x = anything other than 1 or 5 Done!

What I want it to do is when x = anything between 1-5 to output Small! then Done! Or if it is between 5-infinity to output Big! then Done! but if the number is not 1 or 5 it just outputs Done! What changes should I do to my code?

How can I use if-else statement in c#?

I would like to create a console application. In this application user have to type number between 1 and 9. I am using asscii code for reach the numbers. But my IF statement not works correctly. In the second statement, it always returns true. Where am I doing wrong?

// Get the ascii number of the key the user has entered.
int userInputAscii = Console.Read();

// Convert userInput to integer
string userInput = Char.ConvertFromUtf32(userInputAscii);

if (userInputAscii > 48 && userInputAscii < 58) 
{
  Console.WriteLine("Correct!");
}
else if (userInputAscii > 57 || userInputAscii < 48)
{
 Console.WriteLine("Wrong characters! Try again.");
}

I want to onchage "change" just one time

so: I've been trying to make an onchange change just one time, because i want the object appear on the screen after the first change, and stay on the screen:

<select required name="Tamanho" style="margin-top: 10px;margin-bottom: 10px;font-family: bebas_kairegular;font-size: 26px;" onchange="button();">
    <option value="tamanho" selected disabled id="tamanho">Escolha um tamanho</option>
    <option value="P">P</option>
    <option value="M">M</option>
    <option value="G">G</option>
</select>

<div id="button" ><button type="button" onclick="cartClick()" style="font-size: 26px;">Comprar</button></div>

and used this javascript function to appear the div on the page

  function button() {
  var p = document.getElementById("button");
  if (p.style.display === "none") {
    p.style.display = "block";
  } else {
    p.style.display = "none
  }
 }
button();

I don't know what to do to have what i want. Help me please?

Thank You!

Can if-structures be used in Haskell list comprehensions?

Can some sort of if statement be used inside list comprehension to determine one of several outcomes for each element of a list?

Say I have a list comprehension over a list that contains elements which are either a 0 or a 1.

If the value is a 0, then the string "off" needs to be stored in another list in the same position. If the value is 1 then "on".

This is just an example. It looks easily done with recursion, but what if this needs to be done on a list of lists? Or lists of lists of lists?

if else to create a new column by new categorial

I am trying to create a new column in a table from another one, this new column is a categorization of time intervals. I created a function to calculate the time intervals from the other column. Below is the function and error:

def calc_interval(df):
    if (enq2020.TEMPO_REL_ANOS[(enq2020['TEMPO_REL_ANOS']<=1)]):
        return 'menos de um 1 ano'
    elif (enq2020.TEMPO_REL_ANOS[(enq2020['TEMPO_REL_ANOS']>1) &(enq2020['TEMPO_REL_ANOS']<=2.5 )]):
        return 'entre 1 e 2.5 anos '
    elif (enq2020.TEMPO_REL_ANOS[(enq2020['TEMPO_REL_ANOS']>2.5) &(enq2020['TEMPO_REL_ANOS']<=5 )]):
        return 'entre 2.5 e 5 anos '
    elif( enq2020.TEMPO_REL_ANOS[(enq2020['TEMPO_REL_ANOS']>5) &(enq2020['TEMPO_REL_ANOS']<=10 )]):
        return 'entre 5 e 10 anos'
    elif enq2020.TEMPO_REL_ANOS[ (enq2020['TEMPO_REL_ANOS'])>10]:
        return 'mais de 10 anos'
enq2020['INTERVAL_REL']=enq2020['TEMPO_REL_ANOS'].apply(calc_interval,axis=1)
                     
          TypeError: calc_interval() got an unexpected keyword argument 'axis'
        

bash script with if condition [closed]

I want this in this script To make sure that the certificate is created for the domain either www or none www before it is created, and if he did not create it, he should try again -------------------

                /usr/local/bin/add-virtualhost create $1 $2
          sitesAvailabledomainSSL=/etc/apache2/sites-available/$2-le-ssl.conf
       if [ ! -e "$sitesAvailabledomainSSL" ]; then
      echo 1 | certbot -d "$1"
      else
        echo 1 | certbot --expand -d "$3"
        fi

           virtualHostStart='### start virtual host'
            virtualHostStart="${virtualHostStart} ${1}"
           virtualHostEnd='### end virtual host'
           virtualHostEnd="${virtualHostEnd} ${1}"

###   regular expression to remove wrong virtual host from the SSL file
sed -zE -i "s/<IfModule mod_ssl.c>(\r\n|\r|\n)<VirtualHost \*\:80>(\r\n|\r|\n)$virtualHostStart.* 
$virtualHostEnd(\r\n|\r|\n)<\/VirtualHost>(\r\n|\r|\n)<\/IfModule>//" /etc/apache2/sites- 
available/$2-le-ssl.conf

 ### restart Apache
 /etc/init.d/apache2 reload
------------------

any ideas?

PHP else/if statement, with rand() [duplicate]

I try to solve this exercise, but Im not sure how to look for the solution. For my current knowledge my program should print out smg, but I get only error .

Error message :

     
Warning: Undefined variable $x in /in/NVFqg on line 6
Charile bit your finger!

Here is my code :

<?php 
function isBitten()
{

if ($x <= 50) { // line 6 //
   echo "Charile bit your finger!"; 
   $x = rand(0, 100);
}

else {
  echo "Charlie did not bite your finger";
}



  }

 ?>



<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Charlie</title>
  </head>
  <body>


     <?php
     isBitten();
      ?>

  </body>
</html>

Your help is much appreciated! Thank you!