mercredi 1 avril 2020

How to check if student wrote a bad word? [closed]

I have a dictionary of all curse words. I want a student to write any statement and the program should display whether student cursed or not.

 internal void CheckIfStudentDidntCursed()
{
    var cursedwords = File.ReadAllLines("C:\\Users\\Lenovo\\source\\repos\\CS-labs\\CS-lab\\data\\wulgaryzmy.txt");

    Console.WriteLine("Write a statement: ");
     Console.ReadLine();
    {
        if (Console.ReadLine() )
        {
            Console.WriteLine("Student cursed.");
        }
        else
        {
            Console.WriteLine("Student did not curse.");
        }
    }
}

I am a begginer and I need some advice.

Program to check if alphabet is vowel or consonent

I am a beginner in python and trying to write a program to find if alphabet is vowel or consonant using list and for loop

The code is as follows:

    al=input("Enter the alphabet")

    list=['a','e','i','o','u']


    for p in list:
      if al==p:
          print("The alphabet is a vowel")


    else:
      print("The alphabet is a consonant")

The output is:

C:\Users\dell\PycharmProjects\HelloWorld\venv\Scripts\python.exe

C:/Users/dell/PycharmProjects/HelloWorld/app.py

Enter the alphabete

Process finished with exit code 0

Could someone tell me where i am going wrong

Button response issues for a Simon Says game

Ive been developing a Simon says game recently that adds to the score if you click the correct button which there are 3, 1) green 1 2) red 2 3) trick

I've noticed that when I run the game and click the appropriate buttons only one will add to the score whilst the other two subtract from it (Regardless of what the statement says). Im unsure why this is the case and was wondering if anyone had any insights). My thought is that the if functions don't seem to correlate to the new statement that is generated.

Any suggestions are appreciated,

Javascript:

var answers = [
    "Simon says click red !", 
    "Simon says click green !",
    "Simon says click 1 !", 
    "Simon says click 2 !", 
    "Click green",
    "Click red", 
    "Click 1", 
    "Click 2!"
];

var score = 0;
var total = document.getElementById("score");
var statement  = document.getElementById("instruct");
var randomStatement = answers[Math.floor(Math.random() * answers.length)];



function refresh(){
    var randomStatement = answers[Math.floor(Math.random() * answers.length)];
    statement.innerHTML = randomStatement;
}

function pressTrick(){
if(randomStatement === "Click green" || randomStatement === "Click red" || randomStatement === "Click 1" || randomStatement === "Click2!"){
    score++;
    total.style.color = "green";
    total.innerHTML = "Total score: " + score;
    setTimeout(refresh,900);
} else {
    total.style.color = "red";
    score--;
    total.innerHTML = "Total score: " + score;
    setTimeout(refresh,900);

}
}

function pressRed(){
    if(randomStatement === "Simon says click red !" || randomStatement === "Simon says click 2 !"){
    score++;
    total.style.color = "green";
    total.innerHTML = "Total score: " + score;
    setTimeout(refresh,900);    
}  else {
   total.style.color = "red";
   score--;
   total.innerHTML = "Total score: " + score;
   setTimeout(refresh,900);


}}


function pressGreen(){
    if(randomStatement === "Simon says click 1 !" || randomStatement === "Simon says click green !"){
    score++;
    total.style.color = "green";
    total.innerHTML = "Total score: " + score;
    setTimeout(refresh,900);
}   else {
    total.style.color = "red";
    score--;
    total.innerHTML = "Total score: " + score;
    setTimeout(refresh,900);

}}

function  start(){
    var i = 60;
    var count = setInterval(timer,1000);
    refresh();



function timer() {
    var display = document.getElementById("timer");
    var finished = document.getElementById("heading");


    if(i < 1){
   clearInterval(count);
   finished.innerHTML = "Game Over! Your final Score is : " + score;
   display.style.color = "red";
   display.style.fontWeight = "bold";
   document.body.style.backgroundColor = "black";

} else if(i <= 10) {
    i--;
   display.style.color = " red";
   display.style.fontWeight = "bold";
   display.innerHTML =  i + " Seconds Left";
} else  {
    i--;
    display.style.color = "green";
    display.style.fontWeight = "bold";
    display.innerHTML =  i + " Seconds Left";  
}}}

HTML:

<html>
    <head>
        <title> Simon Says! </title>
        <link rel = "stylesheet" href = "simonsays.css"/>
    </head>
    <body>

    </br>
        <h1> Test Your Reflexes! </h1>
        <div id = "heading"; class = "h2"> Click on Simon to Begin! </div>
    </br> 
        <img src = "boy.jpg" onclick = "start()"; onclick = "timer()"; onclick = "returnStatement";/>
    </br>
    <div id = "instruct" class="statement"></div>
</br>
        <div class = "align">
        <input type = "button" class = "button2" id = "button2" value = "1" onclick = "pressGreen()"; ></input> 
        <input type = "button" class = "button" id = "button" value = "2" onclick = "pressRed()"; ></input>
        <input type = "button" class = "button3" id = "button3 " value = "Trick" onclick = "pressTrick()";></input>
</div>
</br>
        <div id = "score" class = "score"><b> Score: </b></div>
        <div id = "timer" class = "timer"><b> Time left: </b></div>
        <script src = "simonsays.js"></script>
    </body>


</html>

Thank you!

How to fix else systax else in python? [closed]

I'm novice in python. I do this code to say if funcCode is different from 5 and 6 do this : r.append(p['ModbusADURequest'][1].startAddr) else do r.append(p['ModbusADURequest'][1]. registerAddr) but I have an error " File "parserz.py", line 868 else: ^ SyntaxError: invalid syntax"

def reg_no_list(s):
r = []
for p in s:
    if (p['ModbusADUResponse'][1].funcCode != int("0x06", 16)) and (p['ModbusADUResponse'][1].funcCode != int("0x05", 16)):

        if p.haslayer('ModbusADURequest'):
            try:
                r.append(p['ModbusADURequest'][1].startAddr)
            except AttributeError:
                pass
    return r
    else:
        r.append(p['ModbusADURequest'][1]. registerAddr)
                except AttributeError:
                    pass
        return r

Any help please ? Thanks in advance

cs(24,7): error CS1519: Invalid token 'else' in class, struct, or interface member declaration

I am following this tutorial: https://www.youtube.com/watch?v=1QfxdUpVh5I I am also getting this error: "cs(27,2): error CS1513: } expected" This is my first game and I am fairly new to this so please be patient. Here is the code

 {
     public float timeBtwAttack;
     public float startTimeBtwAttack;
         void Update()
     {
        if(timeBtwAttack <= 0)
         {
             if (Input.GetKey(KeyCode.Space))
             {
                 Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemies);
                 for (int i = 0; i < enemiesToDamage.Length; i++)
                 {
                     enemiesToDamage[i].GetComponent<Enemy>().TakeDamage(damage);
                 }
             }
         }
         timeBtwAttack = startTimeBtwAttack;

     } else {


 }

Java using return value from method for if else statements

I made a method in java that prints a menu screen that looks like this:

MENU
c - Number of whitespace characters
f - Find text
r - Replace all !'s
q - Quit

Choose an option:

The method returns a char. How do I use the return value of the method in main to make if else statements?

printMenu method:

public static char printMenu(Scanner scnr) {
      char menuOp;

      //display the menu
      System.out.println("\nMENU");
      System.out.println( "c - Number of whitespace characters");
      System.out.println("f - Find text");
      System.out.println("r - Replace all !\'s");
      System.out.println("q - Quit\n");

      menuOp = ' ';

      //loop until the user has entered a c, f, r or q
      while (menuOp != 'c' && menuOp != 'f' &&
                menuOp != 'r' &&  
                menuOp != 'q') {
         System.out.println( "Choose an option:");
         menuOp = scnr.nextLine().charAt(0);
      }

      //return the letter that the user entered
      return menuOp;
   }  //end of the printMenu method

What I want to be able to do in main:

while (return value from printMenu method != 'q'){

      printMenu(scnr);
      if (return value from printMenu method == 'c'){ //do this                    
      }
      else if (return value from printMenu method == 'f'){ //do this
      }
      else if (return value from printMenu method == 'r'){ //do this
      }
   }
}

I'm still new and really appreciate the help, patience, and kindness. Thanks

Edit - I have to use the return value from printMenu() as a requirement for a project.

Finde a speciific cell and filter by column

I have question how to write a code that finde specific cell and then select the all row.

For example I will finde the values in column uber(Vsota) and check the value in CasNapake(Vsota)(here I will select the biggest value). If the cell in the row 0 - column uber(Vsota) 17 is not the same that in next column- 1 than I will select all row 0. The next step In the next cuolumns (1,2,3,4) we have 4 the same numbers, in this case I will check the column **CasNapake(Vsota) and select the biggest value ( 36) and copy only the the biggest row (row number 4). I will do this for the all list and then selectet rows paste in another list

I am thenter image description here]1]1**

Example:

         STENR1                text1               soll uber    STESTART1        
                                                                                       STEENDE1               CasNapake 
        M1320.4     waiting for pouring machine     45  17  1. 02. 2020 00:00:47    1. 02. 2020 00:01:15        28
        M1320.4     waiting for pouring machine     45  40  1. 02. 2020 00:01:51    1. 02. 2020 00:02:21        30
        M1323.1     modell change activ (drag)      45  40  1. 02. 2020 00:02:05    1. 02. 2020 00:02:39        34
        M1323.2     modell change activ (cope)      45  40  1. 02. 2020 00:02:40    1. 02. 2020 00:02:44        4
        M1911.3     ALS quantity reached            45  40  1. 02. 2020 00:01:30    1. 02. 2020 00:02:06        36
        M1320.3     waiting for safety door         45  25  1. 02. 2020 00:03:45    1. 02. 2020 00:03:49        4
        M1323.2     modell change activ (cope)      45  25  1. 02. 2020 00:02:40    1. 02. 2020 00:03:24        44
        M1320.3     waiting for safety door         45  14  1. 02. 2020 00:04:11    1. 02. 2020 00:04:29        18
        M1320.3     waiting for safety door         45  3   1. 02. 2020 00:05:56    1. 02. 2020 00:06:02        6
        M1320.3     waiting for safety door         45  10  1. 02. 2020 00:05:56    1. 02. 2020 00:06:02        6
        M1925.2     pouring maschine is waiting     45  20  1. 02. 2020 00:08:24    1. 02. 2020 00:08:28        4
        E0162.0     piercing device z-axis not      45  188 1. 02. 2020 00:12:19    1. 02. 2020 00:12:19        0
        M1320.4     waiting for pouring machine     45  188 1. 02. 2020 00:10:06    1. 02. 2020 00:11:09        63
        M1320.4     waiting for pouring machine     45  188 1. 02. 2020 00:11:50    1. 02. 2020 00:12:13        23
        M1925.2     pouring maschine is waiting for 45  188 1. 02. 2020 00:08:24    1. 02. 2020 00:10:05        101
        E0131.6     core setter stop HvO +3.2       45  15  1. 02. 2020 00:12:53    1. 02. 2020 00:13:17        24

The result table:

               STENR1                  text1       soll uber    STESTART1        
                                                                                       STEENDE1               CasNapake 
        M1320.4     waiting for pouring machine     45  17  1. 02. 2020 00:00:47    1. 02. 2020 00:01:15        28

        M1911.3     ALS quantity reached            45  40  1. 02. 2020 00:01:30    1. 02. 2020 00:02:06        36

        M1323.2     modell change activ (cope)      45  25  1. 02. 2020 00:02:40    1. 02. 2020 00:03:24        44
        M1320.3     waiting for safety door         45  14  1. 02. 2020 00:04:11    1. 02. 2020 00:04:29        18
        M1320.3     waiting for safety door         45  3   1. 02. 2020 00:05:56    1. 02. 2020 00:06:02        6
        M1320.3     waiting for safety door         45  10  1. 02. 2020 00:05:56    1. 02. 2020 00:06:02        6
        M1925.2     pouring maschine is waiting     45  20  1. 02. 2020 00:08:24    1. 02. 2020 00:08:28        4

        M1925.2     pouring maschine is waiting for 45  188 1. 02. 2020 00:08:24    1. 02. 2020 00:10:05        101
        E0131.6     core setter stop HvO +3.2       45  15  1. 02. 2020 00:12:53    1. 02. 2020 00:13:17        24

enter image description here