Homeworks: testing conditions

IF homework (hw1)

This is the first official homework you get! In this homework we are going to do some simple changes to a perl program, like we did during the last lab session.

If you have Linux on your laptop you can download the program and change it with a text editor like we did in the lab. Note that your Linux may be a little different, so you may need to looks for the Terminal and the Text Editor, but they are there somewhere. If you do not have Linux yet, you can use codepad. This task is coded “hw1“.

while ($total < 100) {
   $random = int(rand(13));
   $total = $total + $random;
   print " This time the special number is $random.\n";
}
print " Finished: I choosed $howmany random numbers, the total is $total.\n";

Your task is to modify the script so that:

  1. The variable “$howmany” will contain the number of random numbers printed (so that at the end the total of lines printed will be shown as needed.
  2. If the random number generated can be divided by 3 a “lucky you” text is added in the message printed.

How to submit your work

Once you checked that your script is okay, you must submit the work done filling this form. Remember to put your login ID, and the correct homework ID (this is hw1, okay?). In this case you can just put the final script on the first box (perl script 01).
In the future you might be required to produce more than one script.

Tagged ,

7 thoughts on “Homeworks: testing conditions

  1. Roberta says:

    Ciao!
    non ho capito il secondo punto, cioè come fare per dividere il numero per 3! ho provato anche creando un array con tutti i multipli ma non mi riesce!
    Grazie mille!

    • proch says:

      Ciao, ti ricordi quando abbiamo verificato se un numero fosse pari o dispari?
      Alias, ricordi l’operatore matematico “resto della divisione”?

  2. Roberta says:

    Ciao!! Non riesco a capire come fare per vedere se il numero che è uscito in $howmany è divisibile per tre! ho provato anche creando un array con i multipli all’interno…ma niente!!!
    Grazie mille!

    • proch says:

      Ciao Roberta,
      è esattamente come fatto in laboratorio quando volevamo distinguere numeri pari e dispari (= divisibili per 2 con resto zero).
      Ricordi l’operatore “resto della divisione”?

  3. Roberta says:

    Grazie mille x il consiglio.. infine avevo capito che bisognava guardare il resto! Grazie ancora..

    • proch says:

      Welcome!
      Scusa ma non mi ero accorto che avevi fatto entrambe le domande, altrimenti non avrei risposto due volte 🙂
      …Dal pannello di controllo non vedo le faccine, bisognera’ rimediare…

Leave a Reply to After Lab03: homeworks | Perl & Genomics Cancel reply

Your email address will not be published. Required fields are marked *